Fix a possible use-after-free in custom_exts_free
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 20 Nov 2023 09:05:49 +0000 (10:05 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 22 Nov 2023 08:36:54 +0000 (09:36 +0100)
This may happen when ssl_cert_dup calls custom_exts_copy, where
a possible memory allocation error causes custom_exts_free
to be called twice: once in the error handling of custom_exts_copy
and a second time in the error handling of ssl_cert_dup.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22772)

(cherry picked from commit bc0773bbbd4d3ace6957385f1f22a5cda25dc94f)

ssl/statem/extensions_cust.c

index 73b82fc7de2d3361560fd93af7aaeaa1ef851bbd..d75ee7df662b36b653ab51745892bf8e458a7789 100644 (file)
@@ -333,6 +333,8 @@ void custom_exts_free(custom_ext_methods *exts)
         OPENSSL_free(meth->parse_arg);
     }
     OPENSSL_free(exts->meths);
+    exts->meths = NULL;
+    exts->meths_count = 0;
 }
 
 /* Return true if a client custom extension exists, false otherwise */