summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2023-04-27 02:54:38 +0200
committerPauli <pauli@openssl.org>2023-05-01 09:14:42 +0200
commit0feb90ba6093a59dcea0279d699169f604600d49 (patch)
tree148676b8787c439570435e7062037255fd5c74d3 /crypto
parentbuild_wincrypt_test.c: Fix compilation with MSVC (diff)
downloadopenssl-0feb90ba6093a59dcea0279d699169f604600d49.tar.xz
openssl-0feb90ba6093a59dcea0279d699169f604600d49.zip
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)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/asn1/a_strnid.c4
-rw-r--r--crypto/asn1/asn_mime.c8
2 files changed, 10 insertions, 2 deletions
diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c
index 869ac82714..998468f846 100644
--- a/crypto/asn1/a_strnid.c
+++ b/crypto/asn1/a_strnid.c
@@ -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);
diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c
index a26eac1731..898c204fbc 100644
--- a/crypto/asn1/asn_mime.c
+++ b/crypto/asn1/asn_mime.c
@@ -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: