summaryrefslogtreecommitdiffstats
path: root/src/crypto/obj/obj.c
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2015-05-11 17:20:37 -0700
committerKenny Root <kroot@google.com>2015-05-12 23:06:14 +0000
commite9ada863a7b3e81f5d2b1e3bdd2305da902a87f5 (patch)
tree6e43e34595ecf887c26c32b86d8ab097fe8cac64 /src/crypto/obj/obj.c
parentb3106a0cc1493bbe0505c0ec0ce3da4ca90a29ae (diff)
downloadexternal_boringssl-e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5.zip
external_boringssl-e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5.tar.gz
external_boringssl-e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5.tar.bz2
external/boringssl: bump revision.
This change bumps the BoringSSL revision to the current tip-of-tree. Change-Id: I91d5bf467e16e8d86cb19a4de873985f524e5faa
Diffstat (limited to 'src/crypto/obj/obj.c')
-rw-r--r--src/crypto/obj/obj.c69
1 files changed, 30 insertions, 39 deletions
diff --git a/src/crypto/obj/obj.c b/src/crypto/obj/obj.c
index b04321b..511aba3 100644
--- a/src/crypto/obj/obj.c
+++ b/src/crypto/obj/obj.c
@@ -68,21 +68,26 @@
#include <openssl/thread.h>
#include "obj_dat.h"
+#include "../internal.h"
-/* These globals are protected by CRYPTO_LOCK_OBJ. */
+
+static struct CRYPTO_STATIC_MUTEX global_added_lock = CRYPTO_STATIC_MUTEX_INIT;
+/* These globals are protected by |global_added_lock|. */
static LHASH_OF(ASN1_OBJECT) *global_added_by_data = NULL;
static LHASH_OF(ASN1_OBJECT) *global_added_by_nid = NULL;
static LHASH_OF(ASN1_OBJECT) *global_added_by_short_name = NULL;
static LHASH_OF(ASN1_OBJECT) *global_added_by_long_name = NULL;
+static struct CRYPTO_STATIC_MUTEX global_next_nid_lock =
+ CRYPTO_STATIC_MUTEX_INIT;
static unsigned global_next_nid = NUM_NID;
static int obj_next_nid(void) {
int ret;
- CRYPTO_w_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_write(&global_next_nid_lock);
ret = global_next_nid++;
- CRYPTO_w_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_next_nid_lock);
return ret;
}
@@ -130,7 +135,7 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o) {
if (o->sn != NULL) {
sn = OPENSSL_strdup(o->sn);
- if (sn) {
+ if (sn == NULL) {
goto err;
}
}
@@ -145,15 +150,9 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o) {
err:
OPENSSL_PUT_ERROR(OBJ, OBJ_dup, ERR_R_MALLOC_FAILURE);
- if (ln != NULL) {
- OPENSSL_free(ln);
- }
- if (sn != NULL) {
- OPENSSL_free(sn);
- }
- if (data != NULL) {
- OPENSSL_free(data);
- }
+ OPENSSL_free(ln);
+ OPENSSL_free(sn);
+ OPENSSL_free(data);
OPENSSL_free(r);
return NULL;
}
@@ -195,17 +194,17 @@ int OBJ_obj2nid(const ASN1_OBJECT *obj) {
return obj->nid;
}
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_data != NULL) {
ASN1_OBJECT *match;
match = lh_ASN1_OBJECT_retrieve(global_added_by_data, obj);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match->nid;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
nid_ptr = bsearch(obj, kNIDsInOIDOrder, NUM_OBJ, sizeof(unsigned), obj_cmp);
if (nid_ptr == NULL) {
@@ -237,18 +236,18 @@ static int short_name_cmp(const void *key, const void *element) {
int OBJ_sn2nid(const char *short_name) {
const unsigned int *nid_ptr;
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_short_name != NULL) {
ASN1_OBJECT *match, template;
template.sn = short_name;
match = lh_ASN1_OBJECT_retrieve(global_added_by_short_name, &template);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match->nid;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
nid_ptr = bsearch(short_name, kNIDsInShortNameOrder, NUM_SN, sizeof(unsigned), short_name_cmp);
if (nid_ptr == NULL) {
@@ -271,18 +270,18 @@ static int long_name_cmp(const void *key, const void *element) {
int OBJ_ln2nid(const char *long_name) {
const unsigned int *nid_ptr;
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_long_name != NULL) {
ASN1_OBJECT *match, template;
template.ln = long_name;
match = lh_ASN1_OBJECT_retrieve(global_added_by_long_name, &template);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match->nid;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
nid_ptr = bsearch(long_name, kNIDsInLongNameOrder, NUM_LN, sizeof(unsigned), long_name_cmp);
if (nid_ptr == NULL) {
@@ -324,18 +323,18 @@ const ASN1_OBJECT *OBJ_nid2obj(int nid) {
return &kObjects[nid];
}
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_nid != NULL) {
ASN1_OBJECT *match, template;
template.nid = nid;
match = lh_ASN1_OBJECT_retrieve(global_added_by_nid, &template);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
err:
OPENSSL_PUT_ERROR(OBJ, OBJ_nid2obj, OBJ_R_UNKNOWN_NID);
@@ -543,15 +542,11 @@ int OBJ_obj2txt(char *out, int out_len, const ASN1_OBJECT *obj, int dont_return_
}
}
- if (bl) {
- BN_free(bl);
- }
+ BN_free(bl);
return n;
err:
- if (bl) {
- BN_free(bl);
- }
+ BN_free(bl);
return -1;
}
@@ -600,7 +595,7 @@ static int obj_add_object(ASN1_OBJECT *obj) {
obj->flags &= ~(ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
ASN1_OBJECT_FLAG_DYNAMIC_DATA);
- CRYPTO_w_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_write(&global_added_lock);
if (global_added_by_nid == NULL) {
global_added_by_nid = lh_ASN1_OBJECT_new(hash_nid, cmp_nid);
global_added_by_data = lh_ASN1_OBJECT_new(hash_data, cmp_data);
@@ -623,7 +618,7 @@ static int obj_add_object(ASN1_OBJECT *obj) {
if (obj->ln != NULL) {
ok &= lh_ASN1_OBJECT_insert(global_added_by_long_name, &old_object, obj);
}
- CRYPTO_w_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return ok;
}
@@ -662,12 +657,8 @@ int OBJ_create(const char *oid, const char *short_name, const char *long_name) {
op = NULL;
err:
- if (op != NULL) {
- ASN1_OBJECT_free(op);
- }
- if (buf != NULL) {
- OPENSSL_free(buf);
- }
+ ASN1_OBJECT_free(op);
+ OPENSSL_free(buf);
return ret;
}