public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Fix null-pointer dereference in nano-malloc
@ 2022-01-26 12:14 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2022-01-26 12:14 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=73d515fcfecd1004ccffef8fcd0c7223b9eec6ab

commit 73d515fcfecd1004ccffef8fcd0c7223b9eec6ab
Author: Cyril Yared <yaredcyril@gmail.com>
Date:   Tue Jan 25 07:44:10 2022 -0800

    Fix null-pointer dereference in nano-malloc
    
    If p is NULL, then the free_list is empty and we should return the
    correct failure values.

Diff:
---
 newlib/libc/stdlib/nano-mallocr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c
index 6fb08a616..0c5fb2885 100644
--- a/newlib/libc/stdlib/nano-mallocr.c
+++ b/newlib/libc/stdlib/nano-mallocr.c
@@ -322,7 +322,7 @@ void * nano_malloc(RARG malloc_size_t s)
                 r=r->next;
             }
 
-            if ((char *)p + p->size == (char *)_SBRK_R(RCALL 0))
+            if (p != NULL && (char *)p + p->size == (char *)_SBRK_R(RCALL 0))
             {
                /* The last free item has the heap end as neighbour.
                 * Let's ask for a smaller amount and merge */


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

only message in thread, other threads:[~2022-01-26 12:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 12:14 [newlib-cygwin] Fix null-pointer dereference in nano-malloc Corinna Vinschen

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 read-only IMAP folder(s) and NNTP newsgroup(s).