diff options
author | op <> | 2024-08-26 22:00:47 +0000 |
---|---|---|
committer | op <> | 2024-08-26 22:00:47 +0000 |
commit | 60298806bf99f206c5f6cfe260a00f54b00e0583 (patch) | |
tree | 88025f57256ede618a651f2d3b849dd2a5dac8a7 /src/lib/libcrypto/dh | |
parent | 4f06d42711ea4c0d56fc2f9d133a8c12889eaf93 (diff) | |
download | openbsd-60298806bf99f206c5f6cfe260a00f54b00e0583.tar.gz openbsd-60298806bf99f206c5f6cfe260a00f54b00e0583.tar.bz2 openbsd-60298806bf99f206c5f6cfe260a00f54b00e0583.zip |
replace strtol(3) usage with strtonum(3); idea/ok/tweaks tb@
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r-- | src/lib/libcrypto/dh/dh_pmeth.c | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/src/lib/libcrypto/dh/dh_pmeth.c b/src/lib/libcrypto/dh/dh_pmeth.c index ee90ffe73f..1e5327b11f 100644 --- a/src/lib/libcrypto/dh/dh_pmeth.c +++ b/src/lib/libcrypto/dh/dh_pmeth.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dh_pmeth.c,v 1.16 2024/01/01 16:01:48 tb Exp $ */ | 1 | /* $OpenBSD: dh_pmeth.c,v 1.17 2024/08/26 22:00:47 op Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -58,6 +58,7 @@ | |||
58 | 58 | ||
59 | #include <limits.h> | 59 | #include <limits.h> |
60 | #include <stdio.h> | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | ||
61 | #include <string.h> | 62 | #include <string.h> |
62 | 63 | ||
63 | #include <openssl/asn1t.h> | 64 | #include <openssl/asn1t.h> |
@@ -153,36 +154,21 @@ pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) | |||
153 | static int | 154 | static int |
154 | pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) | 155 | pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) |
155 | { | 156 | { |
156 | long lval; | 157 | const char *errstr; |
157 | char *ep; | ||
158 | int len; | 158 | int len; |
159 | 159 | ||
160 | if (!strcmp(type, "dh_paramgen_prime_len")) { | 160 | if (!strcmp(type, "dh_paramgen_prime_len")) { |
161 | errno = 0; | 161 | len = strtonum(value, INT_MIN, INT_MAX, &errstr); |
162 | lval = strtol(value, &ep, 10); | 162 | if (errstr != NULL) |
163 | if (value[0] == '\0' || *ep != '\0') | 163 | return -2; |
164 | goto not_a_number; | ||
165 | if ((errno == ERANGE && | ||
166 | (lval == LONG_MAX || lval == LONG_MIN)) || | ||
167 | (lval > INT_MAX || lval < INT_MIN)) | ||
168 | goto out_of_range; | ||
169 | len = lval; | ||
170 | return EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len); | 164 | return EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len); |
171 | } else if (!strcmp(type, "dh_paramgen_generator")) { | 165 | } else if (!strcmp(type, "dh_paramgen_generator")) { |
172 | errno = 0; | 166 | len = strtonum(value, INT_MIN, INT_MAX, &errstr); |
173 | lval = strtol(value, &ep, 10); | 167 | if (errstr != NULL) |
174 | if (value[0] == '\0' || *ep != '\0') | 168 | return -2; |
175 | goto not_a_number; | ||
176 | if ((errno == ERANGE && | ||
177 | (lval == LONG_MAX || lval == LONG_MIN)) || | ||
178 | (lval > INT_MAX || lval < INT_MIN)) | ||
179 | goto out_of_range; | ||
180 | len = lval; | ||
181 | return EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, len); | 169 | return EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, len); |
182 | } | 170 | } |
183 | 171 | ||
184 | not_a_number: | ||
185 | out_of_range: | ||
186 | return -2; | 172 | return -2; |
187 | } | 173 | } |
188 | 174 | ||