Why buffer overflow doesn't affect to this code?

前端 未结 5 2014
傲寒
傲寒 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:27

    Buffer overflow is undefined behaviour. It may crash, but no one guarantee that. In most compilers, the stack grows down, so you probably override main's return address, but the call to printf doesn't override your string.

提交回复
热议问题