【发布时间】:2019-10-20 13:07:13
【问题描述】:
我正在尝试为我的安全类做一个缓冲区溢出,我们不允许调用任何函数,我们需要跳转到秘密函数并返回 0 而不会出现分段错误。我编写了下面的代码并成功跳转到秘密,但我遇到了分段错误。如何成功终止程序?或者是否可以只写入单个地址而不是 for 循环,当我尝试它并没有改变任何东西时。
#include <stdio.h>
void secret()
{
printf("now inside secret()!\n");
}
void entrance()
{
int doNotTouch[10];
// can only modify this section BEGIN
// cant call secret(), maybe use secret (pointer to function)
for (int i = 0; i < 14; i++) {
*(doNotTouch + i) = (int) &secret;
}
// can only modify this section END
printf("now inside entrance()!\n");
}
int main (int argc, char *argv[])
{
entrance();
return 0;
}
【问题讨论】:
标签: c pointers segmentation-fault buffer-overflow