一切我閱讀使我相信,這應該引起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