In ossl_get_ocsp_response(), the OCSP_BASICRESP allocated by
OCSP_response_get1_basic() is never freed when the OCSP response
contains zero SingleResponse entries.
The allocation and guard were combined in a single && expression,
so when OCSP_resp_get0(bs, 0) returns NULL, short-circuit evaluation
skips the block containing OCSP_BASICRESP_free(bs), leaking bs on
every handshake with such a response.
Fix by splitting the allocation out of the condition and adding an
else branch that frees bs when the SingleResponse check fails.
Fixes: b1b4b154fd38 "Add support for TLS 1.3 OCSP multi-stapling for server certs"
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
MergeDate: Sat Mar 21 22:26:50 2026
(Merged from https://github.com/openssl/openssl/pull/30463)
* happening because of test cases.
*/
ERR_set_mark();
- if (((bs = OCSP_response_get1_basic(resp)) != NULL)
- && ((sr = OCSP_resp_get0(bs, 0)) != NULL)) {
+ bs = OCSP_response_get1_basic(resp);
+ if (bs != NULL && (sr = OCSP_resp_get0(bs, 0)) != NULL) {
/* use the first single response to get the algorithm used */
cid = (OCSP_CERTID *)OCSP_SINGLERESP_get0_id(sr);
*/
if (i == num)
resp = NULL;
+ } else {
+ OCSP_BASICRESP_free(bs);
}
/*