diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-10-29 14:53:55 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-10-29 14:53:55 +0530 |
commit | 88e316b06414ee7c944cd6f8b30b07a972b78499 (patch) | |
tree | 9ce83580993906710f832135a2efdbecefc6c767 /malloc/tst-malloc-usable.c | |
parent | 1d56fd3baeaa67405b8a1d67275b4c6eecac77b8 (diff) | |
download | glibc-88e316b06414ee7c944cd6f8b30b07a972b78499.tar.gz glibc-88e316b06414ee7c944cd6f8b30b07a972b78499.tar.xz glibc-88e316b06414ee7c944cd6f8b30b07a972b78499.zip |
Handle NULL input to malloc_usable_size [BZ #28506]
Hoist the NULL check for malloc_usable_size into its entry points in malloc-debug and malloc and assume non-NULL in all callees. This fixes BZ #28506 Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Florian Weimer <fweimer@redhat.com> Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Diffstat (limited to 'malloc/tst-malloc-usable.c')
-rw-r--r-- | malloc/tst-malloc-usable.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/malloc/tst-malloc-usable.c b/malloc/tst-malloc-usable.c index a1074b782a..b0d702be10 100644 --- a/malloc/tst-malloc-usable.c +++ b/malloc/tst-malloc-usable.c @@ -2,6 +2,7 @@ MALLOC_CHECK_ exported to a positive value. Copyright (C) 2012-2021 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -21,29 +22,24 @@ #include <malloc.h> #include <string.h> #include <stdio.h> +#include <support/support.h> +#include <support/check.h> static int do_test (void) { size_t usable_size; void *p = malloc (7); - if (!p) - { - printf ("memory allocation failed\n"); - return 1; - } + TEST_VERIFY_EXIT (p != NULL); usable_size = malloc_usable_size (p); - if (usable_size != 7) - { - printf ("malloc_usable_size: expected 7 but got %zu\n", usable_size); - return 1; - } - + TEST_COMPARE (usable_size, 7); memset (p, 0, usable_size); free (p); + + TEST_COMPARE (malloc_usable_size (NULL), 0); + return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include "support/test-driver.c" |