Even though NULL is the holy cow of C programmers, treated very specially by C compilers, technically nothing stops you from doing this.

~ sudo sysctl vm.mmap_min_addr=0
vm.mmap_min_addr = 0

~ cat null.c
#include
#include
#include

int main(void) {
char *addr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
return 1;
}
printf("We have successfully mapped %p\n", addr);
strcpy(addr, "ON NOES YOU HAVE WORMS IN YOUR NULL");
printf("%s\n", NULL);
}
~ gcc null.c -o null
~ ./null

We have successfully mapped (nil)
ON NOES YOU HAVE WORMS IN YOUR NULL

WHERE IS YOUR GOD NOW?

Sign in to participate in the conversation
Librem Social

Librem Social is an opt-in public network. Messages are shared under Creative Commons BY-SA 4.0 license terms. Policy.

Stay safe. Please abide by our code of conduct.

(Source code)

image/svg+xml Librem Chat image/svg+xml