c++ - 强类型能防止缓冲区溢出吗?

标签 c++ buffer-overflow

强类型(在本例中为 char)是否可以防止缓冲区溢出?

char a[100]
char b[100]

strcpy(a,unknownFunction); // unknownFunction could overflow b 
                           // since its length is unknown

strcpy(b,a); // can b still overflow a with its now, 
             // potentially overflowed size?

最佳答案

没有。 strcpy() 会一直运行,直到找到空终止符 ('\0')。如果 b[] 不包含一个,它将遍历随机内存,直到最终找到一个。

关于c++ - 强类型能防止缓冲区溢出吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3629131/

相关文章:

c++ - 在构造函数中分配数组时出错

c++ - utf8 <-> utf16 : codecvt poor performance

C++:返回对象时不解构对象?

c++ - 为什么 while(scanf ("%lld", &num) == 1) 比 while(scanf ("%lld", &num)) 快

c - 如何使用特定的返回地址溢出缓冲区?

c - 执行 malloc 时程序崩溃

c - 使用局部变量查找函数的返回地址

c++ - 尝试理解编译器错误信息 : default member initializer required before the end of its enclosing class

c - ret2libc segfault地址为0x0000000000000000

linux - 缓冲区溢出误解