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.

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

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/musl

	# 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/ http://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


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

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git