summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem
diff options
context:
space:
mode:
authorderaadt <>2014-05-29 21:07:43 +0000
committerderaadt <>2014-05-29 21:07:43 +0000
commit642d45ae22413aa8195b105d051ca8896e782c5d (patch)
treed5fe0c330801f3e72c7b588264c6027636db4330 /src/lib/libcrypto/pem
parentf60b3b3365842d8869513a7e36981671cd726939 (diff)
downloadopenbsd-642d45ae22413aa8195b105d051ca8896e782c5d.tar.gz
openbsd-642d45ae22413aa8195b105d051ca8896e782c5d.tar.bz2
openbsd-642d45ae22413aa8195b105d051ca8896e782c5d.zip
convert 53 malloc(a*b) to reallocarray(NULL, a, b). that is 53
potential integer overflows easily changed into an allocation return of NULL, with errno nicely set if need be. checks for an allocations returning NULL are commonplace, or if the object is dereferenced (quite normal) will result in a nice fault which can be detected & repaired properly. ok tedu
Diffstat (limited to 'src/lib/libcrypto/pem')
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c2
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c4
2 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 58d2bfbee9..945262f019 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -605,7 +605,7 @@ PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
605 goto err; 605 goto err;
606 } 606 }
607 607
608 buf = malloc(PEM_BUFSIZE * 8); 608 buf = reallocarray(NULL, PEM_BUFSIZE, 8);
609 if (buf == NULL) { 609 if (buf == NULL) {
610 reason = ERR_R_MALLOC_FAILURE; 610 reason = ERR_R_MALLOC_FAILURE;
611 goto err; 611 goto err;
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index 92b70157cd..a7b9379223 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -85,7 +85,7 @@ PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
85 if (j > max) 85 if (j > max)
86 max = j; 86 max = j;
87 } 87 }
88 s = (char *)malloc(max*2); 88 s = (char *)reallocarray(NULL, max, 2);
89 if (s == NULL) { 89 if (s == NULL) {
90 PEMerr(PEM_F_PEM_SEALINIT, ERR_R_MALLOC_FAILURE); 90 PEMerr(PEM_F_PEM_SEALINIT, ERR_R_MALLOC_FAILURE);
91 goto err; 91 goto err;
@@ -159,7 +159,7 @@ PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
159 i = RSA_size(priv->pkey.rsa); 159 i = RSA_size(priv->pkey.rsa);
160 if (i < 100) 160 if (i < 100)
161 i = 100; 161 i = 100;
162 s = (unsigned char *)malloc(i*2); 162 s = reallocarray(NULL, i, 2);
163 if (s == NULL) { 163 if (s == NULL) {
164 PEMerr(PEM_F_PEM_SEALFINAL, ERR_R_MALLOC_FAILURE); 164 PEMerr(PEM_F_PEM_SEALFINAL, ERR_R_MALLOC_FAILURE);
165 goto err; 165 goto err;