git: 1e99be5dcda2 - main - libc: lib_malloc_aligned(): add a missing NULL check

From: Maxim Sobolev <sobomax_at_FreeBSD.org>
Date: Sun, 08 Dec 2024 19:15:16 UTC
The branch main has been updated by sobomax:

URL: https://cgit.FreeBSD.org/src/commit/?id=1e99be5dcda222d47a77715e190a381a14f46ece

commit 1e99be5dcda222d47a77715e190a381a14f46ece
Author:     Maxim Sobolev <sobomax@FreeBSD.org>
AuthorDate: 2024-12-08 19:08:43 +0000
Commit:     Maxim Sobolev <sobomax@FreeBSD.org>
CommitDate: 2024-12-08 19:14:36 +0000

    libc: lib_malloc_aligned(): add a missing NULL check
    
    For some reason return value of the __je_bootstrap_malloc()
    is not checked and then de-referenced few lines below, causing
    a SEGV if an early allocation fails.
    
    MFC after:      1 month
---
 lib/libc/gen/tls.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index 3c1a5472c0e5..30b4fc583c98 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -113,6 +113,8 @@ libc_malloc_aligned(size_t size, size_t align)
 		align = sizeof(void *);
 
 	mem = __je_bootstrap_malloc(size + sizeof(void *) + align - 1);
+	if (mem == NULL)
+		return (NULL);
 	res = (void *)roundup2((uintptr_t)mem + sizeof(void *), align);
 	*(void **)((uintptr_t)res - sizeof(void *)) = mem;
 	return (res);