summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rsa/rsa_pmeth.c
diff options
context:
space:
mode:
authorderaadt <>2014-06-12 20:40:57 +0000
committerderaadt <>2014-06-12 20:40:57 +0000
commit95b33f3e2fad03793adf906f7d3b08883ec3684c (patch)
tree44a491147b347caf1b2dd774e13e12db3c08944e /src/lib/libcrypto/rsa/rsa_pmeth.c
parent71477dc340552244618421bfc331e3226e59f4ea (diff)
downloadopenbsd-95b33f3e2fad03793adf906f7d3b08883ec3684c.tar.gz
openbsd-95b33f3e2fad03793adf906f7d3b08883ec3684c.tar.bz2
openbsd-95b33f3e2fad03793adf906f7d3b08883ec3684c.zip
replace atoi() calls with strtol(). Follow the idiomatic pattern in our
manual page strictly. Return -2 if the strings are not strict numbers. The numbers remain in the range of "int". Range checking for these parameters is done later in the pkey_*_ctl() functions, or sometimes in functions much further downstream... but not always!!! ok millert miod mikeb
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_pmeth.c')
-rw-r--r--src/lib/libcrypto/rsa/rsa_pmeth.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_pmeth.c b/src/lib/libcrypto/rsa/rsa_pmeth.c
index a611fc3461..1f9d826014 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.7 2014/06/12 15:49:30 deraadt Exp $ */ 1/* $OpenBSD: rsa_pmeth.c,v 1.8 2014/06/12 20:40:57 deraadt 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 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <limits.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include <openssl/asn1t.h> 62#include <openssl/asn1t.h>
62#include <openssl/x509.h> 63#include <openssl/x509.h>
@@ -518,6 +519,9 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
518static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, 519static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
519 const char *type, const char *value) 520 const char *type, const char *value)
520 { 521 {
522 long lval;
523 char *ep;
524
521 if (!value) 525 if (!value)
522 { 526 {
523 RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_VALUE_MISSING); 527 RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_VALUE_MISSING);
@@ -549,22 +553,35 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
549 return EVP_PKEY_CTX_set_rsa_padding(ctx, pm); 553 return EVP_PKEY_CTX_set_rsa_padding(ctx, pm);
550 } 554 }
551 555
552 if (!strcmp(type, "rsa_pss_saltlen")) 556 if (!strcmp(type, "rsa_pss_saltlen")) {
553 {
554 int saltlen; 557 int saltlen;
555 saltlen = atoi(value); 558
559 errno = 0;
560 lval = strtol(value, &ep, 10);
561 if (value[0] == '\0' || *ep != '\0')
562 goto not_a_number;
563 if ((errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) ||
564 (lval > INT_MAX || lval < INT_MIN))
565 goto out_of_range;
566 saltlen = lval;
556 return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen); 567 return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen);
557 } 568 }
558 569
559 if (!strcmp(type, "rsa_keygen_bits")) 570 if (!strcmp(type, "rsa_keygen_bits")) {
560 {
561 int nbits; 571 int nbits;
562 nbits = atoi(value); 572
573 errno = 0;
574 lval = strtol(value, &ep, 10);
575 if (value[0] == '\0' || *ep != '\0')
576 goto not_a_number;
577 if ((errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) ||
578 (lval > INT_MAX || lval < INT_MIN))
579 goto out_of_range;
580 nbits = lval;
563 return EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, nbits); 581 return EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, nbits);
564 } 582 }
565 583
566 if (!strcmp(type, "rsa_keygen_pubexp")) 584 if (!strcmp(type, "rsa_keygen_pubexp")) {
567 {
568 int ret; 585 int ret;
569 BIGNUM *pubexp = NULL; 586 BIGNUM *pubexp = NULL;
570 if (!BN_asc2bn(&pubexp, value)) 587 if (!BN_asc2bn(&pubexp, value))
@@ -573,10 +590,12 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx,
573 if (ret <= 0) 590 if (ret <= 0)
574 BN_free(pubexp); 591 BN_free(pubexp);
575 return ret; 592 return ret;
576 } 593 }
577 594
595not_a_number:
596out_of_range:
578 return -2; 597 return -2;
579 } 598}
580 599
581static int pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 600static int pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
582 { 601 {