diff options
author | tb <> | 2024-01-04 17:17:40 +0000 |
---|---|---|
committer | tb <> | 2024-01-04 17:17:40 +0000 |
commit | d0e416b67fcb7e23e0f7e1a276beb5d08487dbcd (patch) | |
tree | de49d92dab8766e00318df9a79cf5e893cac50d0 /src | |
parent | 00a41f70d8c4e3330ec5ea9a908795fa95756a7f (diff) | |
download | openbsd-d0e416b67fcb7e23e0f7e1a276beb5d08487dbcd.tar.gz openbsd-d0e416b67fcb7e23e0f7e1a276beb5d08487dbcd.tar.bz2 openbsd-d0e416b67fcb7e23e0f7e1a276beb5d08487dbcd.zip |
Clean up EVP_PKEY_asn1_find_str()
Use slightly better argument and variable names, do not pointlessly try
to match a string of negative length < -1, use a size_t for the strlen()
and preserve the logic that allows lookup by a string fragment rather
than a full string.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/evp/p_lib.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c index d9cb66336c..fdddc49b00 100644 --- a/src/lib/libcrypto/evp/p_lib.c +++ b/src/lib/libcrypto/evp/p_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p_lib.c,v 1.55 2024/01/04 17:08:57 tb Exp $ */ | 1 | /* $OpenBSD: p_lib.c,v 1.56 2024/01/04 17:17:40 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -205,23 +205,32 @@ EVP_PKEY_asn1_find(ENGINE **engine, int pkey_id) | |||
205 | } | 205 | } |
206 | 206 | ||
207 | const EVP_PKEY_ASN1_METHOD * | 207 | const EVP_PKEY_ASN1_METHOD * |
208 | EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len) | 208 | EVP_PKEY_asn1_find_str(ENGINE **engine, const char *str, int len) |
209 | { | 209 | { |
210 | const EVP_PKEY_ASN1_METHOD *ameth; | 210 | const EVP_PKEY_ASN1_METHOD *ameth; |
211 | size_t str_len; | ||
211 | int i; | 212 | int i; |
212 | 213 | ||
214 | if (engine != NULL) | ||
215 | *engine = NULL; | ||
216 | |||
217 | if (len < -1) | ||
218 | return NULL; | ||
213 | if (len == -1) | 219 | if (len == -1) |
214 | len = strlen(str); | 220 | str_len = strlen(str); |
215 | if (pe != NULL) | 221 | else |
216 | *pe = NULL; | 222 | str_len = len; |
217 | for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) { | 223 | |
218 | ameth = EVP_PKEY_asn1_get0(i); | 224 | for (i = 0; i < N_ASN1_METHODS; i++) { |
225 | ameth = asn1_methods[i]; | ||
219 | if (ameth->pkey_flags & ASN1_PKEY_ALIAS) | 226 | if (ameth->pkey_flags & ASN1_PKEY_ALIAS) |
220 | continue; | 227 | continue; |
221 | if (((int)strlen(ameth->pem_str) == len) && | 228 | if (strlen(ameth->pem_str) != str_len) |
222 | !strncasecmp(ameth->pem_str, str, len)) | 229 | continue; |
230 | if (strncasecmp(ameth->pem_str, str, str_len) == 0) | ||
223 | return ameth; | 231 | return ameth; |
224 | } | 232 | } |
233 | |||
225 | return NULL; | 234 | return NULL; |
226 | } | 235 | } |
227 | 236 | ||