Why buffer overflow doesn't affect to this code?

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

    You're not seeing any effect because you don't have any more local variables, change the code to this and you will

    int main(int argc, char *argv[])
    {
        char ch[10];
        int i=42;
    
        printf("String 10 max. :: "); gets( ch );
    
        printf("String: %s\n", ch);
        printf("i: %d\n", i);
    
        return 0;
    }
    

提交回复
热议问题