diff options
| author | op <> | 2024-08-26 22:00:47 +0000 |
|---|---|---|
| committer | op <> | 2024-08-26 22:00:47 +0000 |
| commit | 74733354b5147290f7bc39826a56793e0c4bdcda (patch) | |
| tree | 88025f57256ede618a651f2d3b849dd2a5dac8a7 /src/lib/libcrypto/dh | |
| parent | e1e5814be66e5d7a0471e1c2a690578960c1307f (diff) | |
| download | openbsd-74733354b5147290f7bc39826a56793e0c4bdcda.tar.gz openbsd-74733354b5147290f7bc39826a56793e0c4bdcda.tar.bz2 openbsd-74733354b5147290f7bc39826a56793e0c4bdcda.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 | ||
