Causing a buffer Overflow with fgets

后端 未结 2 1979
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 15:11

I\'m experimenting with buffer overflows and try to overwrite the return address of the stack with a certain input of fgets

This is the code:

void fo         


        
2条回答
  •  迷失自我
    2021-01-11 15:42

    void bar()
    {
        char buf[20];
        puts("Input:");
        fgets(buf, 24, stdin);
        printf("Your input:.\n", strlen(buf));
    }
    

    ... This works and causes a segmentation fault...

    The compiler is probably replacing fgets with a safer variant that includes a check on the destination buffer size. If the check fails, the the prgram unconditionally calls abort().

    In this particular case, you should compile the program with -U_FORTIFY_SOURCE or -D_FORTIFY_SOURCE=0.

提交回复
热议问题