[PATCH 1/1] Fix null-pointer dereference in nano-malloc

Corinna Vinschen vinschen@redhat.com
Wed Jan 26 12:14:29 GMT 2022


On Jan 25 07:44, Cyril Yared wrote:
> If p is NULL, then the free_list is empty and we should return the
> correct failure values.
> ---
>  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 */
> -- 
> 2.21.0 (Apple Git-122.2)

Pushed.


Thanks,
Corinna



More information about the Newlib mailing list