aboutsummaryrefslogtreecommitdiff
path: root/malloc/malloc.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2021-10-29 14:53:55 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2021-10-29 14:53:55 +0530
commit88e316b06414ee7c944cd6f8b30b07a972b78499 (patch)
tree9ce83580993906710f832135a2efdbecefc6c767 /malloc/malloc.c
parent1d56fd3baeaa67405b8a1d67275b4c6eecac77b8 (diff)
downloadglibc-88e316b06414ee7c944cd6f8b30b07a972b78499.zip
glibc-88e316b06414ee7c944cd6f8b30b07a972b78499.tar.gz
glibc-88e316b06414ee7c944cd6f8b30b07a972b78499.tar.bz2
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/malloc.c')
-rw-r--r--malloc/malloc.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 2ba1fee..095d97a 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1,5 +1,6 @@
/* Malloc implementation for multiple threads without lock contention.
Copyright (C) 1996-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
@@ -5007,20 +5008,13 @@ __malloc_trim (size_t s)
static size_t
musable (void *mem)
{
- mchunkptr p;
- if (mem != 0)
- {
- size_t result = 0;
-
- p = mem2chunk (mem);
+ mchunkptr p = mem2chunk (mem);
- if (chunk_is_mmapped (p))
- result = chunksize (p) - CHUNK_HDR_SZ;
- else if (inuse (p))
- result = memsize (p);
+ if (chunk_is_mmapped (p))
+ return chunksize (p) - CHUNK_HDR_SZ;
+ else if (inuse (p))
+ return memsize (p);
- return result;
- }
return 0;
}
@@ -5028,10 +5022,9 @@ musable (void *mem)
size_t
__malloc_usable_size (void *m)
{
- size_t result;
-
- result = musable (m);
- return result;
+ if (m == NULL)
+ return 0;
+ return musable (m);
}
#endif