From e4aa83204502df229def8f1b639039dfa5fe33a1 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Fri, 24 Nov 2023 21:47:28 +0100 Subject: LibC: Fill new allocations with random data and fix a bug The bug was noticed as a result of this new randomization of allocations. --- userland/libc/malloc/malloc.c | 2 ++ userland/libc/stdio/fopen.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'userland') diff --git a/userland/libc/malloc/malloc.c b/userland/libc/malloc/malloc.c index 4c9621b..79d1d5f 100644 --- a/userland/libc/malloc/malloc.c +++ b/userland/libc/malloc/malloc.c @@ -171,6 +171,7 @@ void *int_malloc(size_t s, int align) { rc = c; return rc; } + randomfill(rc, s); return rc; } @@ -221,6 +222,7 @@ void free(void *p) { if (h->flags & IS_FREE) return; + randomfill(p, h->size); h->flags |= IS_FREE; merge_headers(h); } diff --git a/userland/libc/stdio/fopen.c b/userland/libc/stdio/fopen.c index d31082d..71d14db 100644 --- a/userland/libc/stdio/fopen.c +++ b/userland/libc/stdio/fopen.c @@ -44,7 +44,7 @@ FILE *fopen(const char *pathname, const char *mode) { struct stat s; stat(pathname, &s); - FILE *r = malloc(sizeof(FILE)); + FILE *r = calloc(1, sizeof(FILE)); r->read = read_fd; r->write = write_fd; r->seek = seek_fd; -- cgit v1.2.3