下面代码的输出是"溢出",但我没有明确调用该func函数.它是如何工作的?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int copy(char *input)
{
char var[20];
strcpy(var, input);
return 0;
}
int func(void)
{
printf("Overflow\n");
return 0;
}
int main(int argc, char *argv[])
{
char str[] = "AAAABBBBCCCCDDDDEEEEFFFFGGGG";
int *p = (int *)&str[24];
*p = (int)func;
copy(str);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
oua*_*uah 11
该copy函数溢出函数中的var缓冲区并用copy函数的main地址覆盖返回地址func.
当copy函数返回时,它返回函数而不是main在copy函数调用之后返回func.
| 归档时间: |
|
| 查看次数: |
214 次 |
| 最近记录: |