From: Matt Caswell Date: Tue, 13 Dec 2022 14:54:55 +0000 (+0000) Subject: Avoid dangling ptrs in header and data params for PEM_read_bio_ex X-Git-Tag: OpenSSL_1_1_1t~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbcf509bd046b34cca19c766bbddc31683d0858b;p=thirdparty%2Fopenssl.git Avoid dangling ptrs in header and data params for PEM_read_bio_ex In the event of a failure in PEM_read_bio_ex() we free the buffers we allocated for the header and data buffers. However we were not clearing the ptrs stored in *header and *data. Since, on success, the caller is responsible for freeing these ptrs this can potentially lead to a double free if the caller frees them even on failure. Thanks to Dawei Wang for reporting this issue. Based on a proposed patch by Kurt Roeckx. CVE-2022-4450 Reviewed-by: Paul Dale Reviewed-by: Hugo Landau --- diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c index d416d939ead..328c30cdbb2 100644 --- a/crypto/pem/pem_lib.c +++ b/crypto/pem/pem_lib.c @@ -957,7 +957,9 @@ int PEM_read_bio_ex(BIO *bp, char **name_out, char **header, *data = pem_malloc(len, flags); if (*header == NULL || *data == NULL) { pem_free(*header, flags, 0); + *header = NULL; pem_free(*data, flags, 0); + *data = NULL; goto end; } BIO_read(headerB, *header, headerlen);