EMC Interview Question
Software Engineer / Developersstart a fresh process.
char *ptr = (char*) malloc(1);
allocate one byte but the OS gets a full page and attaches it to the process address space.
start dereferencing ptr and incrementing it in an infinite loop, until SEGV gets generated.
while(1){
*ptr++ = NULL;
pagesize++;
}
write a signal handler to catch SIGSEGV, there print out the value of 'pagesize'
----------------
most memory corruption detectors work on the principle that when memory beyond the page allocated is accessed a SEGV is generated, so it replaces calls to malloc with its own malloc call where it places data at the end of the page instead of the beginning, so when a pointer overwrites a buffer, it also crosses the pagelimit and sigsegv is raised, so you get the exact spot of access violation/memory corruption.
start a fresh process.
- Anonymous September 23, 2010char *ptr = (char*) malloc(1);
allocate one byte but the OS gets a full page and attaches it to the process address space.
start dereferencing ptr and incrementing it in an infinite loop, until SEGV gets generated.
while(1){
*ptr++ = NULL;
pagesize++;
}
write a signal handler to catch SIGSEGV, there print out the value of 'pagesize'
----------------
most memory corruption detectors work on the principle that when memory beyond the page allocated is accessed a SEGV is generated, so it replaces calls to malloc with its own malloc call where it places data at the end of the page instead of the beginning, so when a pointer overwrites a buffer, it also crosses the pagelimit and sigsegv is raised, so you get the exact spot of access violation/memory corruption.