summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorop <>2024-08-26 22:00:47 +0000
committerop <>2024-08-26 22:00:47 +0000
commit60298806bf99f206c5f6cfe260a00f54b00e0583 (patch)
tree88025f57256ede618a651f2d3b849dd2a5dac8a7 /src
parent4f06d42711ea4c0d56fc2f9d133a8c12889eaf93 (diff)
downloadopenbsd-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')
-rw-r--r--src/lib/libcrypto/dh/dh_pmeth.c32
-rw-r--r--src/lib/libcrypto/dsa/dsa_pmeth.c33
2 files changed, 19 insertions, 46 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)
153static int 154static int
154pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) 155pkey_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
184not_a_number:
185out_of_range:
186 return -2; 172 return -2;
187} 173}
188 174
diff --git a/src/lib/libcrypto/dsa/dsa_pmeth.c b/src/lib/libcrypto/dsa/dsa_pmeth.c
index 001bdec201..019bee68b2 100644
--- a/src/lib/libcrypto/dsa/dsa_pmeth.c
+++ b/src/lib/libcrypto/dsa/dsa_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_pmeth.c,v 1.19 2023/12/28 22:11:26 tb Exp $ */ 1/* $OpenBSD: dsa_pmeth.c,v 1.20 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>
@@ -244,34 +245,21 @@ pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
244static int 245static int
245pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) 246pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
246{ 247{
247 long lval; 248 const char *errstr;
248 char *ep;
249 249
250 if (!strcmp(type, "dsa_paramgen_bits")) { 250 if (!strcmp(type, "dsa_paramgen_bits")) {
251 int nbits; 251 int nbits;
252 252
253 errno = 0; 253 nbits = strtonum(value, INT_MIN, INT_MAX, &errstr);
254 lval = strtol(value, &ep, 10); 254 if (errstr != NULL)
255 if (value[0] == '\0' || *ep != '\0') 255 return -2;
256 goto not_a_number;
257 if ((errno == ERANGE &&
258 (lval == LONG_MAX || lval == LONG_MIN)) ||
259 (lval > INT_MAX || lval < INT_MIN))
260 goto out_of_range;
261 nbits = lval;
262 return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits); 256 return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits);
263 } else if (!strcmp(type, "dsa_paramgen_q_bits")) { 257 } else if (!strcmp(type, "dsa_paramgen_q_bits")) {
264 int qbits; 258 int qbits;
265 259
266 errno = 0; 260 qbits = strtonum(value, INT_MIN, INT_MAX, &errstr);
267 lval = strtol(value, &ep, 10); 261 if (errstr != NULL)
268 if (value[0] == '\0' || *ep != '\0') 262 return -2;
269 goto not_a_number;
270 if ((errno == ERANGE &&
271 (lval == LONG_MAX || lval == LONG_MIN)) ||
272 (lval > INT_MAX || lval < INT_MIN))
273 goto out_of_range;
274 qbits = lval;
275 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, 263 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA,
276 EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, 264 EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS,
277 qbits, NULL); 265 qbits, NULL);
@@ -280,8 +268,7 @@ pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
280 EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0, 268 EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0,
281 (void *)EVP_get_digestbyname(value)); 269 (void *)EVP_get_digestbyname(value));
282 } 270 }
283not_a_number: 271
284out_of_range:
285 return -2; 272 return -2;
286} 273}
287 274