Consequences of this buffer overflow?

后端 未结 11 2005
悲&欢浪女
悲&欢浪女 2021-01-01 15:44

So here I believe I have a small buffer overflow problem I found when reviewing someone else\'s code. It immediately struck me as incorrect, and potentially dangerous, but a

11条回答
  •  被撕碎了的回忆
    2021-01-01 16:06

    I tried it with heap allocations, variables are not continuous in memory in this case. That is why it is hard to make buffer overflow in this case.

    Buy try it with stack overflow

    #include "stdio.h"
    #include "string.h"
    
    int main()
    {
         unsigned int  y      = (0xFFFFFFFF);
         char buffer[strlen("This string is 27 char long" + 1)];
          unsigned int  x      = (0xFFFFFFFF);
          sprintf(buffer, "This string is 27 char long");
    
          printf("X (%#x) is %#x, Y (%#x) is %#x, buffer '%s' (%#x) \n", &x, x,&y, y, buffer, buffer);
          return 0;
      }
    

    You will see that Y is corrupted.

提交回复
热议问题