如何使用以下Address Sanitizer输出在我的程序中解决此分段错误?

时间:2016-04-06 10:53:37

标签: gcc segmentation-fault gdb g++ sanitizer

这个问题是我上一个问题的续集,目前的状态是我已经获得了地址消毒剂的输出 - 由@Employed Russian建议 - 如下所示。这是我第一次使用地址消毒剂,所以请原谅我是天真的。

==2596== ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff89d67fd0 at pc 0x401f21 bp 0x7fff89d67d00 sp 0x7fff89d67cf8
READ of size 4 at 0x7fff89d67fd0 thread T0
    #0 0x401f20 (/home/ubuntu/tp+0x401f20)
    #1 0x405bac (/home/ubuntu/tp+0x405bac)
    #2 0x406d40 (/home/ubuntu/tp+0x406d40)
    #3 0x7fb5a7d6fec4 (/lib/x86_64-linux-gnu/libc-2.19.so+0x21ec4)
    #4 0x401278 (/home/ubuntu/tp+0x401278)
Address 0x7fff89d67fd0 is located at offset 320 in frame <TMV_multiplication> of T0's stack:
This frame has 13 object(s):
   [32, 60) 'A11_Upper_matrix'
   [96, 124) 'A_Upper_matrix'
   [160, 192) 'A11_Lower_matrix'
   [224, 256) 'A_Lower_matrix'
   [288, 320) 'VecA'
   [352, 384) 'VecB'
   [416, 448) 'VecC'
   [480, 536) 'result_A_Upper'
   [576, 632) 'result_C_Upper'
   [672, 732) 'matrix_A21'
   [768, 832) 'result_A_Lower'
   [864, 928) 'result_B'
   [960, 1024) 'result_C_Lower'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
  (longjmp and C++ exceptions *are* supported)
Shadow bytes around the buggy address:
0x1000713a4fa0: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
0x1000713a4fb0: 00 00 f4 f4 f2 f2 f2 f2 00 00 00 04 f2 f2 f2 f2
0x1000713a4fc0: 00 00 00 00 f3 f3 f3 f3 00 00 00 00 00 00 00 00
0x1000713a4fd0: 00 00 f1 f1 f1 f1 00 00 00 04 f2 f2 f2 f2 00 00
0x1000713a4fe0: 00 04 f2 f2 f2 f2 00 00 00 00 f2 f2 f2 f2 00 00
=>0x1000713a4ff0: 00 00 f2 f2 f2 f2 00 00 00 00[f2]f2 f2 f2 00 00
0x1000713a5000: 00 00 f2 f2 f2 f2 00 00 00 00 f2 f2 f2 f2 00 00
0x1000713a5010: 00 00 00 00 00 f4 f2 f2 f2 f2 00 00 00 00 00 00
0x1000713a5020: 00 f4 f2 f2 f2 f2 00 00 00 00 00 00 00 04 f2 f2
0x1000713a5030: f2 f2 00 00 00 00 00 00 00 00 f2 f2 f2 f2 00 00
0x1000713a5040: 00 00 00 00 00 00 f2 f2 f2 f2 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
   Addressable:           00
   Partially addressable: 01 02 03 04 05 06 07 
   Heap left redzone:     fa
   Heap righ redzone:     fb
   Freed Heap region:     fd
   Stack left redzone:    f1
   Stack mid redzone:     f2
   Stack right redzone:   f3
   Stack partial redzone: f4
   Stack after return:    f5
   Stack use after scope: f8
   Global redzone:        f9
   Global init order:     f6
   Poisoned by user:      f7
   ASan internal:         fe
==2596== ABORTING

正如之前@Employed Russian指出的那样,很可能问题在于堆栈。现在,如何解决这个堆栈问题?因为这些都是我的头脑。

2 个答案:

答案 0 :(得分:1)

  

我在X[16], Y[16], Z[16] ...中有三个无符号的int数组main   X[32]=Z[0]

您可以在此处停止

访问X的有效索引是0到15.当您访问X[16](及更高版本)时,您正在调用未定义的行为(任何事情都可能发生)。

认为你实际上并不是指你分配给X[32]。您可能意味着&X[32]&Z[0]相同。如果是这种情况,那就没有什么特别有趣的了:数组一个接一个地放在内存中。

  

0x000000008304ed6a in ?? ()

这通常意味着堆栈损坏(某些东西覆盖了返回地址,然后你又回到了无处的中间)。假设X是一个本地数组,写入它超出界限极可能导致这种损坏。

查找此类堆栈损坏的简便方法是使用Address Sanitizer(可用于Clang和GCC)。

<强>更新

Address Sanitizer错误告诉您

  • TMV_multiplication()中,您有一个32字节的本地数组VecA(可能是int VecA[8];)和
  • 您可以访问(读取)该数组超出范围(尝试访问偏移量320,即刚刚超过该数组的末尾)。

此错误不是导致崩溃的原因。你应该修复它,然后重新运行。在此之后还有更多错误。一旦你解决了所有问题,你的程序就会停止崩溃。

答案 1 :(得分:0)

感谢地址清理工具的输出,但是为什么要删除源?

无论如何,如果我没错,输出会告诉您var allRecords = Ext.getCmp('overviewGrid').store.data; var today = new Date(); //and loop like this allRecords.each( function(record){ var start = record.data.start_date; var end = record.data.end_date; if(Ext.Date.format(end, 'Y-m-d') == Ext.Date.format(today, 'Y-m-d')); { Ext.toast({ html: 'Expiring Licenses', title: 'Licenses', width: 200, align: 't', autoClose: false }); } }); 中有访问权限,超出范围。