From 05fde60d896475df638e603c28f63e8c46055639 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 7 Dec 2023 14:14:21 +0000 Subject: [PATCH] Fix potential double-free in calloc selftest Where calloc returns two references to the same buffer, avoid calling free() on both references by setting one to NULL. Signed-off-by: David Horstmann --- programs/test/selftest.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/programs/test/selftest.c b/programs/test/selftest.c index 2b78a8c9f..b9ba1e452 100644 --- a/programs/test/selftest.c +++ b/programs/test/selftest.c @@ -83,6 +83,7 @@ static int calloc_self_test(int verbose) if (verbose) { mbedtls_printf(" CALLOC(0,1): passed (same non-null)\n"); } + empty2 = NULL; } else { if (verbose) { mbedtls_printf(" CALLOC(0,1): passed (distinct non-null)\n"); @@ -107,6 +108,7 @@ static int calloc_self_test(int verbose) if (verbose) { mbedtls_printf(" CALLOC(1,0): passed (same non-null)\n"); } + empty2 = NULL; } else { if (verbose) { mbedtls_printf(" CALLOC(1,0): passed (distinct non-null)\n"); @@ -123,6 +125,7 @@ static int calloc_self_test(int verbose) mbedtls_printf(" CALLOC(1): failed (same buffer twice)\n"); } ++failures; + buffer2 = NULL; } else { if (verbose) { mbedtls_printf(" CALLOC(1): passed\n");