堆栈缓冲区溢出并输出字符

时间:2018-11-18 07:41:05

标签: stack buffer overflow stack-overflow buffer-overflow

static const int answer = 0x21072107;

int main(int argc, char **argv)
{   
    setvbuf(stdin,  NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);

    int x = 0;
    char buffer[32];

    printf("What do you want to put in buffer? ");
    fflush(stdout); 
    gets(buffer);

    printf("\nExpected value of x: %x\n", answer);
    printf("Actual value of x: %x\n", x);
        fflush(stdout);

    if(x == answer)
    {
        printf("\nYou win!\n");
            fflush(stdout);
    }
    else
    {
        printf("Try again!\n");
            fflush(stdout);
        return 1;
    }

    return 0;
}

基于上面的代码,我试图猜测正确的答案。我尝试输入“ A” * 50次,我认为缓冲区将溢出。我有点卡住了,因为我不知道该再输入什么才能猜出正确的答案。有任何提示或帮助吗?

0 个答案:

没有答案