mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] Fix crash in malloc_usable_size() if nullptr
@ 2020-11-25  7:53 Dominic Chen
  0 siblings, 0 replies; only message in thread
From: Dominic Chen @ 2020-11-25  7:53 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 223 bytes --]

Please CC me on replies.

According to the manual for malloc_usable_size(), zero should be 
returned if the input pointer is NULL. Currently, this is not checked, 
which can result in SIGSEGV at runtime.

Thanks,

Dominic


[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 396 bytes --]

diff --git a/src/malloc/mallocng/malloc_usable_size.c b/src/malloc/mallocng/malloc_usable_size.c
index a440a4ea..ce6a960c 100644
--- a/src/malloc/mallocng/malloc_usable_size.c
+++ b/src/malloc/mallocng/malloc_usable_size.c
@@ -3,6 +3,7 @@
 
 size_t malloc_usable_size(void *p)
 {
+	if (!p) return 0;
 	struct meta *g = get_meta(p);
 	int idx = get_slot_index(p);
 	size_t stride = get_stride(g);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-25  7:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25  7:53 [musl] [PATCH] Fix crash in malloc_usable_size() if nullptr Dominic Chen

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).