Why buffer overflow doesn't affect to this code?

前端 未结 5 1966
傲寒
傲寒 2021-01-26 15:09

I have the following code:

int main(int argc, char *argv[])
{
    char ch[10];
    printf(\"String 10 max. :: \"); gets( ch );

    printf(\"String: %s\\n\", ch)         


        
5条回答
  •  广开言路
    2021-01-26 15:37

    A Buffer overflow only causes a "crash" (i.e., a segmentation fault), if you are trying to read/write from a page that has not been mapped. In that case, the memory management unit catches the error.

    If you did not yet reach the end of the page, like in your example, the memory at that point is still valid from the operating system's/processor's point of view - you are just overwriting memory that might be used by another variable.

提交回复
热议问题