我通过以下链接在线阅读以下代码:http://www.cse.scu.edu/~tschwarz/coen152_05/Lectures/BufferOverflow.html
我对此行中%p的使用感到困惑:
printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
Run Code Online (Sandbox Code Playgroud)
这是从这段代码中获取的:
/*
StackOverrun.c
This program shows an example of how a stack-based
buffer overrun can be used to execute arbitrary code. Its
objective is to find an input string that executes the function bar.
*/
#pragma check_stack(off)
#include <string.h>
#include <stdio.h>
void foo(const char* input)
{
char buf[10];
printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n");
strcpy(buf, input);
printf("%s\n", buf);
printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
}
void bar(void)
{
printf("Augh! I've been hacked!\n"); …Run Code Online (Sandbox Code Playgroud) 如果您在 C 中有这样的结构:
struct mystruct{
int i;
char c;
};
Run Code Online (Sandbox Code Playgroud)
你也是:
mystruct m;
m.i = 5;
m.c = 'i';
Run Code Online (Sandbox Code Playgroud)
您是在堆上还是在堆栈上创建结构?