asn1: sort stacks before using find

a_strnid.c doesn't have a lock for the sort.  This is no worse than the
existing code which sorted silently without a lock.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/20842)
This commit is contained in:
Pauli 2023-04-27 10:54:38 +10:00
parent b5a635dc21
commit 0feb90ba60
2 changed files with 10 additions and 2 deletions

View File

@ -133,7 +133,9 @@ ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
fnd.nid = nid;
if (stable) {
if (stable != NULL) {
/* Ideally, this would be done under lock */
sk_ASN1_STRING_TABLE_sort(stable);
idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
if (idx >= 0)
return sk_ASN1_STRING_TABLE_value(stable, idx);

View File

@ -679,7 +679,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
char linebuf[MAX_SMLEN];
MIME_HEADER *mhdr = NULL, *new_hdr = NULL;
STACK_OF(MIME_HEADER) *headers;
int len, state, save_state = 0;
int i, len, state, save_state = 0;
headers = sk_MIME_HEADER_new(mime_hdr_cmp);
if (headers == NULL)
@ -785,6 +785,12 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
break; /* Blank line means end of headers */
}
/* Sort the headers and their params for faster searching */
sk_MIME_HEADER_sort(headers);
for (i = 0; i < sk_MIME_HEADER_num(headers); i++)
if ((mhdr = sk_MIME_HEADER_value(headers, i)) != NULL
&& mhdr->params != NULL)
sk_MIME_PARAM_sort(mhdr->params);
return headers;
err: