Code: Select all
char *linebuf = malloc(1024);
struct line *lobj = malloc( sizeof (struct line) );
Glibc can discover out-of-bounds write behavior when it detects the heap corruption, but it's after event, and the assertion it throws out is not very useful.
How about put *lobj to another heap which is far away from common heap, it seems C library doesn't provide such API, but we can use mmap() to allocate memory far away from sbrk() area and default mmap() area, like, at 2.5GB address.
Code: Select all
char *linebuf = malloc(1024);
void *another_heap = mmap(0x100000*2560, 0x1000,
PROT_WRITE | PROT_READ,
MAP_PRIVATE|MAP_ANONYMOUS, -1,0););
struct line *lobj = another_heap;
Such mechanism can't eliminate or supress out-of-bouds writing, but the debug will be easier. (wired pointer not considered here).
I know the best method to avoid 'out-of-bouds' writing is to keep clear mind when programming, but this seems to be a good mechanism in the initial(buggy) stage of the development, just as assert().
I want to hear from you ~