为什么缓冲区溢出不会影响到这一code? [英] Why buffer overflow doesn't affect to this code?

查看:153
本文介绍了为什么缓冲区溢出不会影响到这一code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

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

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

    return 0;
}

当我与12345678运行此为 CH 运行良好。奇怪的是,当我和123456789012345678901234567890跑!第二个的printf 打印所有字符串(30个字符)到屏幕上。

When I run this with "12345678" as ch it runs well. The strange thing is when I run with "123456789012345678901234567890"! The second printf prints ALL the string (the 30 chars) to the screen.

为什么会出现这种情况?为什么我的code崩溃?

Why does this happen? Why doesn't my code crash?

您的时间,结果谢谢
阿兹台克

Thanks for your time,
Azteca

推荐答案

您没有看到任何效果,因为你没有任何更多的局部变量,改变code到这一点,你会

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;
}

这篇关于为什么缓冲区溢出不会影响到这一code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆