简单地说:
($esp) = 0xbffff49c。ret指令,该指令以Cannot access memory at address 0x90909094.0x90909094当堆栈顶部的值是 时,gdb 尝试访问的原因是0xbffff49c什么?
随机信息(以防万一):
[----------------------------------registers-----------------------------------]
EAX: 0x5a ('Z')
EBX: 0xb7fbeff4 --> 0x15ed7c
ECX: 0xbffff428 --> 0xb7fbf4e0 --> 0xfbad2a84
EDX: 0xb7fc0360 --> 0x0
ESI: 0x0
EDI: 0x0
EBP: 0x90909090
ESP: 0xbffff49c --> 0xbffff450 --> 0xdb31c031
EIP: 0x80485dd (<greeting+113>: ret)
EFLAGS: 0x292 (carry parity ADJUST zero SIGN trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
0x80485d0 <greeting+100>: mov DWORD PTR [esp],0x80487f4
0x80485d7 <greeting+107>: call 0x80483f0 …Run Code Online (Sandbox Code Playgroud) 我正在编写一个toString方法,它打印输出指向结构的指针的所有属性.在阅读处理字符串的安全方法时,我最终创建了以下解决方案:注意Person结构具有属性名称,权重,高度和年龄(除了名称之外的所有整数,这是一个char数组).
char* toString(struct Person* inputPerson)
{
// Allocate memory to return string
char* ret = malloc(sizeof (char) * 100);
// copy "Name: " into string
strcpy(ret, "Name: ");
// safely copy name, at most leaving enough room for the other params (leaving 50 bytes)
strncat(ret, inputPerson->name, 100-50);
// copy "Age: " into string
strcat(ret, "\n\tAge: ");
// create tmp char to allow us to convert ints age, weight, and height into strings
char tmp[4];
// safely convert string to int …Run Code Online (Sandbox Code Playgroud)