【发布时间】:2017-06-02 04:21:44
【问题描述】:
我读到的所有内容都让我相信这应该会导致stack buffer overflow,但事实并非如此:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
char password[8];
int correctPassword = 0;
printf("Password \n");
gets(password);
if(strcmp(password, "password"))
{
printf ("Wrong password entered, root privileges not granted... \n");
}
else
{
correctPassword = 1;
}
if(correctPassword)
{
printf ("Root privileges given to the user \n");
}
return 0;
}
但这是我的输出:
在这种情况下,testtesttesttesttest 显然大于 8 个字符,并且根据source,它应该会导致stack buffer overflow,但事实并非如此。这是为什么呢?
【问题讨论】:
-
因为它是未定义的行为,所以任何事情都可能发生。 stackoverflow.com/documentation/c/364/….
-
您希望堆栈溢出如何体现?当我运行它时,我得到以下输出:
Wrong password entered, root privileges not granted... *** stack smashing detected ***: ./Overflow terminated -
p &password[8]和p &correctPassword显示什么? -
@merlin2011:如果你在没有堆栈保护的情况下编译它,它就有更好的工作机会。
-
没有“堆栈缓冲区溢出”之类的东西。有“堆栈溢出”和“缓冲区溢出”。不清楚你在问什么。
标签: c stack-overflow