diff options
author | Omar Polo <op@cvs.openbsd.org> | 2024-08-26 22:00:48 +0000 |
---|---|---|
committer | Omar Polo <op@cvs.openbsd.org> | 2024-08-26 22:00:48 +0000 |
commit | 0a855dc2e7b98910b3b440077af707d52b0a95e2 (patch) | |
tree | 9193c3c01e6ca8633945658f63d189081c325bcc /lib/libcrypto/dh | |
parent | 9666cd48e54d4ea7c01c4b510393551f164d0f52 (diff) |
replace strtol(3) usage with strtonum(3); idea/ok/tweaks tb@
Diffstat (limited to 'lib/libcrypto/dh')
-rw-r--r-- | lib/libcrypto/dh/dh_pmeth.c | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/lib/libcrypto/dh/dh_pmeth.c b/lib/libcrypto/dh/dh_pmeth.c index ee90ffe73f2..1e5327b11fc 100644 --- a/lib/libcrypto/dh/dh_pmeth.c +++ b/lib/libcrypto/dh/dh_pmeth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh_pmeth.c,v 1.16 2024/01/01 16:01:48 tb Exp $ */ +/* $OpenBSD: dh_pmeth.c,v 1.17 2024/08/26 22:00:47 op Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -58,6 +58,7 @@ #include <limits.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <openssl/asn1t.h> @@ -153,36 +154,21 @@ pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) static int pkey_dh_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) { - long lval; - char *ep; + const char *errstr; int len; if (!strcmp(type, "dh_paramgen_prime_len")) { - errno = 0; - lval = strtol(value, &ep, 10); - if (value[0] == '\0' || *ep != '\0') - goto not_a_number; - if ((errno == ERANGE && - (lval == LONG_MAX || lval == LONG_MIN)) || - (lval > INT_MAX || lval < INT_MIN)) - goto out_of_range; - len = lval; + len = strtonum(value, INT_MIN, INT_MAX, &errstr); + if (errstr != NULL) + return -2; return EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len); } else if (!strcmp(type, "dh_paramgen_generator")) { - errno = 0; - lval = strtol(value, &ep, 10); - if (value[0] == '\0' || *ep != '\0') - goto not_a_number; - if ((errno == ERANGE && - (lval == LONG_MAX || lval == LONG_MIN)) || - (lval > INT_MAX || lval < INT_MIN)) - goto out_of_range; - len = lval; + len = strtonum(value, INT_MIN, INT_MAX, &errstr); + if (errstr != NULL) + return -2; return EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, len); } -not_a_number: -out_of_range: return -2; } |