Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Program won't crash when it should

Name: Anonymous 2012-01-16 3:24

(GCC C)
I ran a pointer over each member of an integer array, storing one character of input in each cell.

The program seems to consistently crash when I try to store X+3 or more characters, where X is the size of the array, but if I do not exceed X+2 it will not crash.

Why does it crashes exactly at the point it does, but not for X+1 or X+2?

Name: Anonymous 2012-01-16 17:21

>>17
He is obviously posting a program which only behaves in a specific way when compiled and run on a specific compiler and architecture. I actually suspect the behavior will differ greatly even within the same compiler if different settings were used when compiling. You have the C standard and within that, the behavior his program will have is undefined, however while that wouldn't be conforming C, it doesn't mean it doesn't have very precise semantics when using a specific compiler with specific settings on a specific architecture - you can almost always determine them when you have fully specified the environment, and when you can determine them, undefined behavior will be fully defined. If your program accidentally uses some undefined behavior (such as a stack overflow), you can blame the author for having made that error, but in practice, if you want to know if your error is exploitable by others, or how to exploit it, you must understand exactly what your program does - this can be done by examining the machine code the compiler generated, and that also has very precise semantics.

>>1
Most small overflows won't cause crashes as a typical ``crash'' is an unhandled exception or signal such as an "memory access violation" or "segmentation fault" which means you've tried to access a page of memory which is not allocated, and usually the stack's memory is allocated in bulk, so an overflow isn't typically fatal, and in some OSes, stacks are growable (this tends to be done by allocating a page where the stack is supposed to grow and setting the memory's protection flags in such a way as to cause an exception or segfault to be generated, which a handler installed by the OS or compiler (depends on implementation again) will then unprotect, allocate some some more memory and set new flags, then seamlessly continue your program like nothing happened at all), which means you would have to keep growing the stack for quite some time until a stack overflow would actually occur (until one reaches a limit imposed by the OS or compiler, usually such a limit is changable).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List