update master-with-bazel from master branch

This commit is contained in:
BoringSSL Robot
2024-02-23 16:27:31 +00:00
+12 -17
View File
@@ -72,6 +72,7 @@ typedef struct lookup_dir_hashes_st {
} BY_DIR_HASH;
typedef struct lookup_dir_entry_st {
CRYPTO_MUTEX lock;
char *dir;
int dir_type;
STACK_OF(BY_DIR_HASH) *hashes;
@@ -156,6 +157,7 @@ static int by_dir_hash_cmp(const BY_DIR_HASH *const *a,
static void by_dir_entry_free(BY_DIR_ENTRY *ent) {
if (ent != NULL) {
CRYPTO_MUTEX_cleanup(&ent->lock);
OPENSSL_free(ent->dir);
sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);
OPENSSL_free(ent);
@@ -215,15 +217,12 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) {
if (!ent) {
return 0;
}
CRYPTO_MUTEX_init(&ent->lock);
ent->dir_type = type;
ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);
ent->dir = OPENSSL_malloc(len + 1);
if (!ent->dir || !ent->hashes) {
by_dir_entry_free(ent);
return 0;
}
OPENSSL_strlcpy(ent->dir, ss, len + 1);
if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {
ent->dir = OPENSSL_strndup(ss, len);
if (ent->dir == NULL || ent->hashes == NULL ||
!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {
by_dir_entry_free(ent);
return 0;
}
@@ -232,10 +231,6 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) {
return 1;
}
// g_ent_hashes_lock protects the |hashes| member of all |BY_DIR_ENTRY|
// objects.
static CRYPTO_MUTEX g_ent_hashes_lock = CRYPTO_MUTEX_INIT;
static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
X509_OBJECT *ret) {
union {
@@ -300,7 +295,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
}
if (type == X509_LU_CRL && ent->hashes) {
htmp.hash = h;
CRYPTO_MUTEX_lock_read(&g_ent_hashes_lock);
CRYPTO_MUTEX_lock_read(&ent->lock);
if (sk_BY_DIR_HASH_find(ent->hashes, &idx, &htmp)) {
hent = sk_BY_DIR_HASH_value(ent->hashes, idx);
k = hent->suffix;
@@ -308,7 +303,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
hent = NULL;
k = 0;
}
CRYPTO_MUTEX_unlock_read(&g_ent_hashes_lock);
CRYPTO_MUTEX_unlock_read(&ent->lock);
} else {
k = 0;
hent = NULL;
@@ -341,7 +336,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
// If a CRL, update the last file suffix added for this
if (type == X509_LU_CRL) {
CRYPTO_MUTEX_lock_write(&g_ent_hashes_lock);
CRYPTO_MUTEX_lock_write(&ent->lock);
// Look for entry again in case another thread added an entry
// first.
if (!hent) {
@@ -354,14 +349,14 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
if (!hent) {
hent = OPENSSL_malloc(sizeof(BY_DIR_HASH));
if (hent == NULL) {
CRYPTO_MUTEX_unlock_write(&g_ent_hashes_lock);
CRYPTO_MUTEX_unlock_write(&ent->lock);
ok = 0;
goto finish;
}
hent->hash = h;
hent->suffix = k;
if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) {
CRYPTO_MUTEX_unlock_write(&g_ent_hashes_lock);
CRYPTO_MUTEX_unlock_write(&ent->lock);
OPENSSL_free(hent);
ok = 0;
goto finish;
@@ -371,7 +366,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
hent->suffix = k;
}
CRYPTO_MUTEX_unlock_write(&g_ent_hashes_lock);
CRYPTO_MUTEX_unlock_write(&ent->lock);
}
if (tmp != NULL) {