diff options
author | Pauli <pauli@openssl.org> | 2023-04-27 10:54:38 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-05-01 17:14:42 +1000 |
commit | 0feb90ba6093a59dcea0279d699169f604600d49 (patch) | |
tree | 148676b8787c439570435e7062037255fd5c74d3 /crypto/asn1/asn_mime.c | |
parent | b5a635dc2113e1bc807ea358a670146c813df989 (diff) |
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/asn1/asn_mime.c')
-rw-r--r-- | crypto/asn1/asn_mime.c | 8 |
1 files changed, 7 insertions, 1 deletions
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: |