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 <david.horstmann@arm.com>
This commit is contained in:
David Horstmann 2023-12-07 14:14:21 +00:00
parent f09b837977
commit 05fde60d89

View File

@ -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");