任何程序将检测到C / C ++结构中的缓冲区溢出? [英] Will any programs detect a buffer overflow within a C/C++ structure?

查看:218
本文介绍了任何程序将检测到C / C ++结构中的缓冲区溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的程序:

struct abc
{
    int x[5];
    int y[5];
};

int main()
{
    struct abc test;
    test.y[0] = 10;
    printf("%d", test.x[5]);
}

(距离借
<一href=\"http://stackoverflow.com/questions/8490946/is-it-legal-to-overrun-one-element-of-a-struct-to-view-another\">Is是合法的溢出一个结构的一个元素,以查看另一个?)

<一个href=\"http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CDcQFjAA&url=http://en.wikipedia.org/wiki/BoundsChecker&ei=MuLnTp2BIann0QHbgOHbCQ&usg=AFQjCNFf1gcIUQxCmcJUluAwisCDwpRHfA\"相对=nofollow>的BoundsChecker 不会检测这是一个溢出。有没有将检测这种类型的编程错误的程序吗?

BoundsChecker does not detect this as an overflow. Are there any programs that will detect this type of programming error?

推荐答案

的确,即使开机没有任何特殊标志:

clang does, even with no special flags turned on:

$ clang example.c -o example
example.c:13:18: warning: array index of '5' indexes past the end of an array
      (that contains 5 elements) [-Warray-bounds]
    printf("%d", test.x[5]);
                 ^      ~
example.c:5:5: note: array 'x' declared here
    int x[5];
    ^
1 warning generated.

作为C ++编译时将打印同样的警告。

The same warning is printed when compiling as C++.

这篇关于任何程序将检测到C / C ++结构中的缓冲区溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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