- 论坛徽章:
- 3
|
给你一个关于缓冲区溢出最简单的例子
- $ cat 3.c
- #include <stdio.h>
- int main()
- {
- char s[10];
- int i;
- int j;
- printf("Input a number:\n");
- scanf("%d",&i);
- printf("The number is %d\n\n",i);
- j=i;
- printf("Input a string:\n");
- scanf("%s",s);
- printf("The string is \"%s\"\n\n",s);
- if(i==j)
- printf("OK\n");
- else
- printf("Fuck\n");
- return 0;
- }
- $ gcc 3.c
- $ ./a.out
- Input a number:
- 1
- The number is 1
- Input a string:
- abc
- The string is "abc"
- OK
- $ ./a.out
- Input a number:
- 1
- The number is 1
- Input a string:
- abcdefghijk
- The string is "abcdefghijk"
- Fuck
- $ ./a.out
- Input a number:
- 1
- The number is 1
- Input a string:
- abcdefghijklmnop
- The string is "abcdefghijklmnop"
- Fuck
- Segmentation fault
复制代码 |
|