简体   繁体   English

***检测到堆栈粉碎***:./ asem终止分段错误(核心已转储)

[英]*** stack smashing detected ***: ./asem terminated Segmentation fault (core dumped)

I'm compiling my program and I'm having error: * stack smashing detected * : ./asem terminated Segmentation fault (core dumped) I don't know what I'm doing wrong. 我正在编译程序,但出现错误: *检测到堆栈粉碎* :./asem终止分段错误(核心已转储)我不知道我在做什么错。 My part was to write in zadanie1 with no %0,%1 and %2. 我的部分是用没有%0,%1和%2的zadanie1编写。

#include <stdio.h>

  int main()

  {
     char *x= "abcabab xxabc";
     char *y= "ab";
     char bufor[4];
    asm volatile(
    ".intel_syntax noprefix;"
    "mov ebx,%1;"
    "push ebx;"
    "mov ebx,%2;"
    "push ebx;"
    "mov ebx,%0;"
    "call zadanie1;"
    "jmp wyjscie;"
    "zadanie1:"
    "mov ah,[ebx];"
    "cmp ah,0;"
    "jz wyjscie;"

    "push ebp;"
    "mov ebp,esp;"
    "mov edx,[ebp+8];"
    "mov al,[edx];"

    "compare:"
    "cmp ah,al;"
    "jnz diff;"

    "inc ebx;"
    "mov ah,[ebx];"
    "cmp ah,0;"
    "jz wyjscie;"

    "inc edx;"
    "mov al,[edx];"
    "cmp al,0;"
    "jnz diff;"
    "inc ecx;"
    "mov edx,[ebp+8];"
    "jmp compare;"

    "diff:"
    "inc ebx;"
    "mov ah,[ebx];"
    "cmp ah,0;"
    "jz wyjscie;"
    "inc edx;"
    "mov al,[edx];"
    "jmp compare;"



    "wyjscie:"

    "pop ebx;"
    "mov [ebx],ecx;"
    "pop ebx;"
    "pop ebp;"
    ".att_syntax prefix;"
    :
    :"r"(x),"r"(y), "r"(bufor)
    :"ebx"
);

return 0;

} }

You need to construct the code properly so you can see where the pushes and the pops don't balance. 您需要正确地构建代码,以便可以看到推送和弹出窗口之间不平衡的地方。 In the 4th line of "zadanie1:" you do another "push ebp;" "zadanie1:"的第4行中,您"zadanie1:"执行另一个"push ebp;" yet you still arrive at "wyjscie:" to pop the same number of items from the stack as when you skipped that push. 但是您仍然会到达"wyjscie:"以从堆栈中弹出与跳过该推送相同数量的项目。 Also, do a proper return from a call instead of popping the return address if you want to keep track of the stack maintenance, and gcc has spotted all this. 另外,如果要跟踪堆栈维护情况,请从调用中进行适当的返回,而不要弹出返回地址,并且gcc已发现所有这些情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM