summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2021-07-26 16:54:20 +0000
committertb <>2021-07-26 16:54:20 +0000
commit7dc459d11ac1d80fa7911ea7c3ccf537ae38b49c (patch)
tree8a8b8dbe3ecf8948e1ce068f648ca318908d25af /src/lib
parent41e85456450e2cdde656430cec7bd1e7c140b4cc (diff)
downloadopenbsd-7dc459d11ac1d80fa7911ea7c3ccf537ae38b49c.tar.gz
openbsd-7dc459d11ac1d80fa7911ea7c3ccf537ae38b49c.tar.bz2
openbsd-7dc459d11ac1d80fa7911ea7c3ccf537ae38b49c.zip
Add error checks for i2d_X509_NAME()
This avoids potential malloc(-1) and malloc(0), spotted by schwarze while documenting X509_ocspid_print(). ok schwarze
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index 1cef35dfca..42b00a729a 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_x509.c,v 1.33 2021/07/06 11:26:25 schwarze Exp $ */ 1/* $OpenBSD: t_x509.c,v 1.34 2021/07/26 16:54:20 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -261,10 +261,12 @@ X509_ocspid_print(BIO *bp, X509 *x)
261 in OCSP requests */ 261 in OCSP requests */
262 if (BIO_printf(bp, " Subject OCSP hash: ") <= 0) 262 if (BIO_printf(bp, " Subject OCSP hash: ") <= 0)
263 goto err; 263 goto err;
264 derlen = i2d_X509_NAME(x->cert_info->subject, NULL); 264 if ((derlen = i2d_X509_NAME(x->cert_info->subject, NULL)) <= 0)
265 goto err;
265 if ((der = dertmp = malloc(derlen)) == NULL) 266 if ((der = dertmp = malloc(derlen)) == NULL)
266 goto err; 267 goto err;
267 i2d_X509_NAME(x->cert_info->subject, &dertmp); 268 if (i2d_X509_NAME(x->cert_info->subject, &dertmp) <= 0)
269 goto err;
268 270
269 if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) 271 if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL))
270 goto err; 272 goto err;