linux环境下常见错误分析

1. Killed(已杀死)

     是指操作系统已经应用程序杀死,杀死的原因保存在 /var/log/syslog中,可以通过查看日志得到。杀死原因通常包括"out of memory"等,如果是“out of memory”,则可能是程序内存泄露引起的,或是分配了一个过大的内存空间。

     检查内存是否泄露,可以通过Valgrind工具进行检查。

      valgrind --leak-check=full-output-file outputfile  <path>/program-name

2.Aborted(已放弃)

     出现的原因通常是由于内存访问非法引起的。为了得到出错时的具体信息,包括出错时的调用堆栈,我们可以在程序运行之前运行如下命令:

     ulimit -c unlimited

     这样程序在出错的时候,就会将堆栈等信息显示出来,并将相关信息保存在一个CORE文件当中,该文件保存在应用程序运行时所在的目录。为了得到出错时的上下文环境,可以通过gdb来加载该CORE文件

        gdb<exe-file> <core-file>

或者 gdb <program>

        core-file <core-file-name>

      加载CORE文件后,可以使用bt或者where显示出错时的调用堆栈或者出错时所处的位置。而后使用up或者down显示上一条出错信息和下一条出错信息。

 

3.Stack smashing detected

   如果显示“Stacksmashing detected”,多般是由于数组访问越界所致,因为只有数组的内存分配是在栈上,指针的内存分配是在堆上。

    下面是一个实例:


ab@cd-x:$cat test_overflow.c

#include <stdio.h>

#include <string.h>

 

intcheck_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.outmypass

Access grainted

ab@cd-x:$ ./a.outyourpass

Access grainted

ab@cd-x:$ ./a.outwepass

Access denined

ab@cd-x:$ ./a.outwepassssssssssssssssss

Access grainted

 

ab@cd-x:$gcc -g -fstack-protector test_overflow.c

ab@cd-x:$ ./a.outwepass

Access denined

ab@cd-x:$ ./a.outmypass

Access grainted

ab@cd-x:$ ./a.outyourpass

Access grainted

ab@cd-x:$ ./a.outwepassssssssssssssssss

*** stacksmashing 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-b76ff000rw-p 00000000 00:00 0

b7717000-b7719000rw-p 00000000 00:00 0

bfc1c000-bfc31000rw-p 00000000 00:00 0         [stack]

Aborted

ab@cd-x:$ 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值