一切我阅读使我相信,这应该引起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,但它不。为什么是这样?
因为它是未定义的行为,所以任何事情都可能发生。 https://stackoverflow.com/documentation/c/364/undefined-behavior#t=201706020423447810219。 – Stargateur
您预期堆栈溢出如何显示?当我运行这个时,我得到以下输出:'输入了错误的密码,未授予root权限... ***堆栈检测到***:./溢出终止 ' – merlin2011
'p&password [8]'和'p&correctPassword'显示? – Ryan