Avoid dangling ptrs in header and data params for PEM_read_bio_ex
authorMatt Caswell <matt@openssl.org>
Tue, 13 Dec 2022 14:54:55 +0000 (14:54 +0000)
committerRichard Levitte <levitte@openssl.org>
Fri, 3 Feb 2023 10:22:47 +0000 (11:22 +0100)
commitbbcf509bd046b34cca19c766bbddc31683d0858b
tree250a6b890fbd34634b33f2468bc3dbe6b4bd0053
parent43d8f88511991533f53680a751e9326999a6a31f
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 <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
crypto/pem/pem_lib.c