summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rsa/rsa_pmeth.c
diff options
context:
space:
mode:
authorop <>2024-08-26 22:01:28 +0000
committerop <>2024-08-26 22:01:28 +0000
commitecaaddb84944c0b5282670c1e6dfd04f3cf35c10 (patch)
treeb4380f19ddfae3ecff8a6134f17a46a472cdd415 /src/lib/libcrypto/rsa/rsa_pmeth.c
parent60298806bf99f206c5f6cfe260a00f54b00e0583 (diff)
downloadopenbsd-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.c30
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)
630static int 631static int
631pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) 632pkey_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 }