]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/nolibc/stdlib: fix memory error in realloc()
authorBrennan Xavier McManus <bxmcmanus@gmail.com>
Tue, 9 Jan 2024 23:44:02 +0000 (18:44 -0500)
committerThomas Weißschuh <linux@weissschuh.net>
Wed, 10 Apr 2024 21:19:00 +0000 (23:19 +0200)
Pass user_p_len to memcpy() instead of heap->len to prevent realloc()
from copying an extra sizeof(heap) bytes from beyond the allocated
region.

Signed-off-by: Brennan Xavier McManus <bxmcmanus@gmail.com>
Cc: stable@vger.kernel.org
Reviewed-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Fixes: 0e0ff638400be8f497a35b51a4751fd823f6bd6a ("tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()`")
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/include/nolibc/stdlib.h

index bacfd35c515656cb5afd089df6ca8ced8bd8ff95..5be9d3c7435a80866a74fd1b15a85196852b296a 100644 (file)
@@ -185,7 +185,7 @@ void *realloc(void *old_ptr, size_t new_size)
        if (__builtin_expect(!ret, 0))
                return NULL;
 
-       memcpy(ret, heap->user_p, heap->len);
+       memcpy(ret, heap->user_p, user_p_len);
        munmap(heap, heap->len);
        return ret;
 }