summaryrefslogtreecommitdiff
path: root/lib/libcrypto/pem
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2015-02-10 09:52:36 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2015-02-10 09:52:36 +0000
commit935f03f76968db2c0995f02b41a6492af33d2bb7 (patch)
treedcfcece8bb55f1dd0d507cd28fc0b2d7e521cbb5 /lib/libcrypto/pem
parent4d1e129bc35db3808a66758bef982d7f8be0f5bf (diff)
Replace assert() and OPENSSL_assert() calls with proper error return paths.
Careful review, feedback & ok doug@ jsing@
Diffstat (limited to 'lib/libcrypto/pem')
-rw-r--r--lib/libcrypto/pem/pem_info.c10
-rw-r--r--lib/libcrypto/pem/pem_lib.c14
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/libcrypto/pem/pem_info.c b/lib/libcrypto/pem/pem_info.c
index 9ddcb565969..6fe72ce742e 100644
--- a/lib/libcrypto/pem/pem_info.c
+++ b/lib/libcrypto/pem/pem_info.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pem_info.c,v 1.19 2014/07/11 08:44:49 jsing Exp $ */
+/* $OpenBSD: pem_info.c,v 1.20 2015/02/10 09:52:35 miod Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -361,8 +361,12 @@ PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
}
/* create the right magic header stuff */
- OPENSSL_assert(strlen(objstr) + 23 +
- 2 * enc->iv_len + 13 <= sizeof buf);
+ if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 >
+ sizeof buf) {
+ PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,
+ ASN1_R_BUFFER_TOO_SMALL);
+ goto err;
+ }
buf[0] = '\0';
PEM_proc_type(buf, PEM_TYPE_ENCRYPTED);
PEM_dek_info(buf, objstr, enc->iv_len, (char *)iv);
diff --git a/lib/libcrypto/pem/pem_lib.c b/lib/libcrypto/pem/pem_lib.c
index 1ebae53e74f..e3629762f9c 100644
--- a/lib/libcrypto/pem/pem_lib.c
+++ b/lib/libcrypto/pem/pem_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pem_lib.c,v 1.35 2014/10/22 13:02:04 jsing Exp $ */
+/* $OpenBSD: pem_lib.c,v 1.36 2015/02/10 09:52:35 miod Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -389,7 +389,10 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
}
kstr = (unsigned char *)buf;
}
- OPENSSL_assert(enc->iv_len <= (int)sizeof(iv));
+ if ((size_t)enc->iv_len > sizeof(iv)) {
+ PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, EVP_R_IV_TOO_LARGE);
+ goto err;
+ }
arc4random_buf(iv, enc->iv_len); /* Generate a salt */
/* The 'iv' is used as the iv and as a salt. It is
* NOT taken from the BytesToKey function */
@@ -400,8 +403,11 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
if (kstr == (unsigned char *)buf)
OPENSSL_cleanse(buf, PEM_BUFSIZE);
- OPENSSL_assert(strlen(objstr) + 23 +
- 2 * enc->iv_len + 13 <= sizeof buf);
+ if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > sizeof buf) {
+ PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,
+ ASN1_R_BUFFER_TOO_SMALL);
+ goto err;
+ }
buf[0] = '\0';
PEM_proc_type(buf, PEM_TYPE_ENCRYPTED);