tags:

views:

3588

answers:

5
+2  A: 

You could try to debug the problem using valgrind:

The Valgrind distribution currently includes six production-quality tools: a memory error detector, two thread error detectors, a cache and branch-prediction profiler, a call-graph generating cache profiler, and a heap profiler. It also includes two experimental tools: a heap/stack/global array overrun detector, and a SimPoint basic block vector generator. It runs on the following platforms: X86/Linux, AMD64/Linux, PPC32/Linux, PPC64/Linux, and X86/Darwin (Mac OS X).

hlovdal
A: 

It means that you wrote to some variables on the stack in an illegal way, most likely as the result of a Buffer overflow.

starblue
Is it...a stack overflow?!?!?!. Zomg.
MattC
Sorry, it's 5:00 AM and I had to.
MattC
Stack overflow is the stack smashing into something else. Here it is the other way around: something has smashed into the stack.
Peter Mortensen
+1  A: 

Valgrind would be my first choice, along with something like electric fence.

Badmotorfinger
+4  A: 

Stack Smashing is actually a protection mechanism used by gcc to detect buffer overflow attacks.


 #include <stdio.h>
  2
  3  void func()
  4  {
  5      char array[10];
  6      gets(array);
  7  }
  8
  9 int main(int argc, char **argv)
 10 {
 11              func();
 12 }

An input of string greater than size 10 causes corruption of gcc inbuilt protection canary variable followed by SIGABRT to terminate the program.

You can disable this protection of gcc using option
-fno-stack-protector
while compiling.
In that case you will get a segmentation fault if you try to access illegal memory location. and of course you can detect the point of overflow using tools mentioned above :)

Neeraj
thanks neeraj...
Biswajyoti Das
+1  A: 

Please see this situation.

ab@cd-x:$ cat test_overflow.c 
#include <stdio.h>
#include <string.h>

int check_password(char *password){
    int flag = 0;
    char buffer[20];
    strcpy(buffer, password);

    if(strcmp(buffer, "mypass") == 0){
        flag = 1;
    }
    if(strcmp(buffer, "yourpass") == 0){
        flag = 1;
    }
    return flag;
}

int main(int argc, char *argv[]){
    if(argc >= 2){
        if(check_password(argv[1])){
            printf("%s", "Access grainted\n");
        }else{
            printf("%s", "Access denined\n");
        }
    }else{
        printf("%s", "Please enter password!\n");
    }
}
ab@cd-x:$ gcc -g -fno-stack-protector test_overflow.c 
ab@cd-x:$ ./a.out mypass
Access grainted
ab@cd-x:$ ./a.out yourpass
Access grainted
ab@cd-x:$ ./a.out wepass
Access denined
ab@cd-x:$ ./a.out wepassssssssssssssssss
Access grainted

ab@cd-x:$ gcc -g -fstack-protector test_overflow.c 
ab@cd-x:$ ./a.out wepass
Access denined
ab@cd-x:$ ./a.out mypass
Access grainted
ab@cd-x:$ ./a.out yourpass
Access grainted
ab@cd-x:$ ./a.out wepassssssssssssssssss
*** stack smashing detected ***: ./a.out terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xce0ed8]
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xce0e90]
./a.out[0x8048524]
./a.out[0x8048545]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xc16b56]
./a.out[0x8048411]
======= Memory map: ========
007d9000-007f5000 r-xp 00000000 08:06 5776       /lib/libgcc_s.so.1
007f5000-007f6000 r--p 0001b000 08:06 5776       /lib/libgcc_s.so.1
007f6000-007f7000 rw-p 0001c000 08:06 5776       /lib/libgcc_s.so.1
0090a000-0090b000 r-xp 00000000 00:00 0          [vdso]
00c00000-00d3e000 r-xp 00000000 08:06 1183       /lib/tls/i686/cmov/libc-2.10.1.so
00d3e000-00d3f000 ---p 0013e000 08:06 1183       /lib/tls/i686/cmov/libc-2.10.1.so
00d3f000-00d41000 r--p 0013e000 08:06 1183       /lib/tls/i686/cmov/libc-2.10.1.so
00d41000-00d42000 rw-p 00140000 08:06 1183       /lib/tls/i686/cmov/libc-2.10.1.so
00d42000-00d45000 rw-p 00000000 00:00 0 
00e0c000-00e27000 r-xp 00000000 08:06 4213       /lib/ld-2.10.1.so
00e27000-00e28000 r--p 0001a000 08:06 4213       /lib/ld-2.10.1.so
00e28000-00e29000 rw-p 0001b000 08:06 4213       /lib/ld-2.10.1.so
08048000-08049000 r-xp 00000000 08:05 1056811    /dos/hacking/test/a.out
08049000-0804a000 r--p 00000000 08:05 1056811    /dos/hacking/test/a.out
0804a000-0804b000 rw-p 00001000 08:05 1056811    /dos/hacking/test/a.out
08675000-08696000 rw-p 00000000 00:00 0          [heap]
b76fe000-b76ff000 rw-p 00000000 00:00 0 
b7717000-b7719000 rw-p 00000000 00:00 0 
bfc1c000-bfc31000 rw-p 00000000 00:00 0          [stack]
Aborted
ab@cd-x:$ 

When I disable smashing stack protector there is a case to make my program error. What happen when I used "./a.out wepassssssssssssssssss"

So above to your question the message "** stack smashing detected : xxx" was displayed because smashing stack protector is active and found that there is stack overflow in your program.

Just find out and fix it.

bugbug
there are many misspell in my program
bugbug