mailing list of musl libc
 help / color / mirror / 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.



[-- 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

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ \
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:

code repositories for the project(s) associated with this inbox:

AGPL code for this site: git clone