summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-11-24 21:47:28 +0100
committerAnton Kling <anton@kling.gg>2023-11-24 21:47:28 +0100
commite4aa83204502df229def8f1b639039dfa5fe33a1 (patch)
treebba452bc7238797dc6474ec5c5673f50e27a2dd3 /userland
parent4764846cc2afe0e56f4490e3973b7322c2129e29 (diff)
LibC: Fill new allocations with random data and fix a bug
The bug was noticed as a result of this new randomization of allocations.
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/malloc/malloc.c2
-rw-r--r--userland/libc/stdio/fopen.c2
2 files changed, 3 insertions, 1 deletions
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;