diff options
author | op <> | 2024-08-26 22:01:28 +0000 |
---|---|---|
committer | op <> | 2024-08-26 22:01:28 +0000 |
commit | ecaaddb84944c0b5282670c1e6dfd04f3cf35c10 (patch) | |
tree | b4380f19ddfae3ecff8a6134f17a46a472cdd415 /src/lib/libcrypto/rsa/rsa_pmeth.c | |
parent | 60298806bf99f206c5f6cfe260a00f54b00e0583 (diff) | |
download | openbsd-ecaaddb84944c0b5282670c1e6dfd04f3cf35c10.tar.gz openbsd-ecaaddb84944c0b5282670c1e6dfd04f3cf35c10.tar.bz2 openbsd-ecaaddb84944c0b5282670c1e6dfd04f3cf35c10.zip |
replace atoi(3) usage with strtonum(3); ok/tweaks tb@
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_pmeth.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_pmeth.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_pmeth.c b/src/lib/libcrypto/rsa/rsa_pmeth.c index 9be9079613..a1bdeb3b36 100644 --- a/src/lib/libcrypto/rsa/rsa_pmeth.c +++ b/src/lib/libcrypto/rsa/rsa_pmeth.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_pmeth.c,v 1.40 2023/12/28 21:59:07 tb Exp $ */ | 1 | /* $OpenBSD: rsa_pmeth.c,v 1.41 2024/08/26 22:01:28 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/opensslconf.h> | 64 | #include <openssl/opensslconf.h> |
@@ -630,6 +631,8 @@ pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) | |||
630 | static int | 631 | static int |
631 | pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) | 632 | pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) |
632 | { | 633 | { |
634 | const char *errstr; | ||
635 | |||
633 | if (!value) { | 636 | if (!value) { |
634 | RSAerror(RSA_R_VALUE_MISSING); | 637 | RSAerror(RSA_R_VALUE_MISSING); |
635 | return 0; | 638 | return 0; |
@@ -664,13 +667,24 @@ pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) | |||
664 | saltlen = RSA_PSS_SALTLEN_MAX; | 667 | saltlen = RSA_PSS_SALTLEN_MAX; |
665 | else if (!strcmp(value, "auto")) | 668 | else if (!strcmp(value, "auto")) |
666 | saltlen = RSA_PSS_SALTLEN_AUTO; | 669 | saltlen = RSA_PSS_SALTLEN_AUTO; |
667 | else | 670 | else { |
668 | saltlen = atoi(value); | 671 | saltlen = strtonum(value, 0, INT_MAX, &errstr); |
672 | if (errstr != NULL) { | ||
673 | RSAerror(RSA_R_INVALID_PSS_SALTLEN); | ||
674 | return -2; | ||
675 | } | ||
676 | } | ||
669 | return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen); | 677 | return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen); |
670 | } | 678 | } |
671 | 679 | ||
672 | if (strcmp(type, "rsa_keygen_bits") == 0) { | 680 | if (strcmp(type, "rsa_keygen_bits") == 0) { |
673 | int nbits = atoi(value); | 681 | int nbits; |
682 | |||
683 | nbits = strtonum(value, 0, INT_MAX, &errstr); | ||
684 | if (errstr != NULL) { | ||
685 | RSAerror(RSA_R_INVALID_KEYBITS); | ||
686 | return -2; | ||
687 | } | ||
674 | 688 | ||
675 | return EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, nbits); | 689 | return EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, nbits); |
676 | } | 690 | } |
@@ -702,7 +716,13 @@ pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) | |||
702 | EVP_PKEY_CTRL_MD, value); | 716 | EVP_PKEY_CTRL_MD, value); |
703 | 717 | ||
704 | if (strcmp(type, "rsa_pss_keygen_saltlen") == 0) { | 718 | if (strcmp(type, "rsa_pss_keygen_saltlen") == 0) { |
705 | int saltlen = atoi(value); | 719 | int saltlen; |
720 | |||
721 | saltlen = strtonum(value, 0, INT_MAX, &errstr); | ||
722 | if (errstr != NULL) { | ||
723 | RSAerror(RSA_R_INVALID_PSS_SALTLEN); | ||
724 | return -2; | ||
725 | } | ||
706 | 726 | ||
707 | return EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(ctx, saltlen); | 727 | return EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(ctx, saltlen); |
708 | } | 728 | } |