diff options
| author | schwarze <> | 2021-11-03 14:36:21 +0000 | 
|---|---|---|
| committer | schwarze <> | 2021-11-03 14:36:21 +0000 | 
| commit | 114f2d9532050091280c79a1096dc0fa38b281bc (patch) | |
| tree | 74daf89556979cece1b0c5f4ed185a3ed7f5abda /src/lib/libc | |
| parent | dde146c50469975e7e0c71d8dc5311229d2654b6 (diff) | |
| download | openbsd-114f2d9532050091280c79a1096dc0fa38b281bc.tar.gz openbsd-114f2d9532050091280c79a1096dc0fa38b281bc.tar.bz2 openbsd-114f2d9532050091280c79a1096dc0fa38b281bc.zip | |
Fix five bugs in X509_REQ_to_X509(3):
* memory leak in X509_set_subject_name(ret, X509_NAME_dup(xn));
* memory leak in X509_set_issuer_name(ret, X509_NAME_dup(xn));
* memory leak in X509_set_pubkey(ret, X509_REQ_get_pubkey(r));
* missing return value check of X509_REQ_get_pubkey(r);
* missing return value check of X509_set_pubkey(...);
Some of these bugs have survived for twenty-five years.
I noticed the first two bugs while documenting the function,
then found that a commit in the OpenSSL 1.1.1 branch, which is
still under a free license, fixed all of them in 2016.
In the function X509_REQ_to_X509(3), merge everything worth merging
from OpenSSL 1.1.1, in particular the relevant parts of:
* 222561fe Apr 30 17:33:59 2015 -0400 (err: label cleanup)
* 0517538d Mar 17 00:15:48 2016 +0100 (the bugfix)
* c5137473 Apr 3  23:37:32 2016 +0200 (code simplification)
While here, delete some commented out code that is wrong in
multiple ways and untouched since the SSLeay era.
One code tweak for readability by tb@, and OK tb@.
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/x509/x509_r2x.c | 23 | 
1 files changed, 12 insertions, 11 deletions
| diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c index 143d0f1aa0..b3b8aa75ed 100644 --- a/src/lib/libcrypto/x509/x509_r2x.c +++ b/src/lib/libcrypto/x509/x509_r2x.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: x509_r2x.c,v 1.12 2021/11/01 20:53:08 tb Exp $ */ | 1 | /* $OpenBSD: x509_r2x.c,v 1.13 2021/11/03 14:36:21 schwarze 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 | * | 
| @@ -74,6 +74,7 @@ X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) | |||
| 74 | X509 *ret = NULL; | 74 | X509 *ret = NULL; | 
| 75 | X509_CINF *xi = NULL; | 75 | X509_CINF *xi = NULL; | 
| 76 | X509_NAME *xn; | 76 | X509_NAME *xn; | 
| 77 | EVP_PKEY *pubkey; | ||
| 77 | 78 | ||
| 78 | if ((ret = X509_new()) == NULL) { | 79 | if ((ret = X509_new()) == NULL) { | 
| 79 | X509error(ERR_R_MALLOC_FAILURE); | 80 | X509error(ERR_R_MALLOC_FAILURE); | 
| @@ -88,14 +89,12 @@ X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) | |||
| 88 | goto err; | 89 | goto err; | 
| 89 | if (!ASN1_INTEGER_set(xi->version, 2)) | 90 | if (!ASN1_INTEGER_set(xi->version, 2)) | 
| 90 | goto err; | 91 | goto err; | 
| 91 | /* xi->extensions=ri->attributes; <- bad, should not ever be done | ||
| 92 | ri->attributes=NULL; */ | ||
| 93 | } | 92 | } | 
| 94 | 93 | ||
| 95 | xn = X509_REQ_get_subject_name(r); | 94 | xn = X509_REQ_get_subject_name(r); | 
| 96 | if (X509_set_subject_name(ret, X509_NAME_dup(xn)) == 0) | 95 | if (X509_set_subject_name(ret, xn) == 0) | 
| 97 | goto err; | 96 | goto err; | 
| 98 | if (X509_set_issuer_name(ret, X509_NAME_dup(xn)) == 0) | 97 | if (X509_set_issuer_name(ret, xn) == 0) | 
| 99 | goto err; | 98 | goto err; | 
| 100 | 99 | ||
| 101 | if (X509_gmtime_adj(xi->validity->notBefore, 0) == NULL) | 100 | if (X509_gmtime_adj(xi->validity->notBefore, 0) == NULL) | 
| @@ -104,14 +103,16 @@ X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) | |||
| 104 | (long)60 * 60 * 24 * days) == NULL) | 103 | (long)60 * 60 * 24 * days) == NULL) | 
| 105 | goto err; | 104 | goto err; | 
| 106 | 105 | ||
| 107 | X509_set_pubkey(ret, X509_REQ_get_pubkey(r)); | 106 | if ((pubkey = X509_REQ_get0_pubkey(r)) == NULL) | 
| 107 | goto err; | ||
| 108 | if (!X509_set_pubkey(ret, pubkey)) | ||
| 109 | goto err; | ||
| 108 | 110 | ||
| 109 | if (!X509_sign(ret, pkey, EVP_md5())) | 111 | if (!X509_sign(ret, pkey, EVP_md5())) | 
| 110 | goto err; | 112 | goto err; | 
| 111 | if (0) { | 113 | return ret; | 
| 114 | |||
| 112 | err: | 115 | err: | 
| 113 | X509_free(ret); | 116 | X509_free(ret); | 
| 114 | ret = NULL; | 117 | return NULL; | 
| 115 | } | ||
| 116 | return (ret); | ||
| 117 | } | 118 | } | 
