malloc() does not properly allocate memory for sizes larger than 1706 bytes.
Created by: Tommoa
I noticed this while trying to calloc()
a buffer of 4096 bytes and it was causing a segmentation fault.
After some trial and error, it turns out that whenever I tried to allocate more than 1706 bytes, the memset()
portion would cause a segmentation fault at some point. I have included the code that I used to cause this error and the compilation step.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv) {
int amount = 0x6ab; // 0x6aa works
printf("%d\n", amount);
char *mem = calloc(amount, 1);
free(mem);
return 0;
}
gcc -fno-stack-protector -Wall -nostdinc -nostdlib -I include -I target/include target/debug/libcrt0.a "test.c" target/debug/libc.a; ./a.out