How about store 'structure' and 'buffer' in different heap?
Posted: Tue Jun 27, 2017 2:02 am
During my programming on a text parser( write in C), i got an idea that we can put data structure far away from 'text buffer' in linear space.
Then *linebuf and *lobj will probably be neighbors in linear space. And, since the insert/delete/paste operations on a text buffer is quite frequently, if an out-of-bounds write to his neighbor *lobj occurs, the debug will be difficult.
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.
We put our important data structures there.(just like an island).
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 ~
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 ~