如何使用以下 Address Sanitizer 输出解决我程序中的此分段错误?
How to resolve this segmentation fault in my program with the following Address Sanitizer output?
这个问题是我上一个问题的 sequel,目前的状态是我已经获得了地址清理器的输出——@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 之前指出的那样,问题很可能出在堆栈上。现在,如何解决这个堆栈问题?因为这些都在我头上。
I have three unsigned int arrays X[16], Y[16], Z[16]
in the main
...
X[32]=Z[0]
你可以就在这里。
访问 X
的有效索引是 0 到 15。当您访问 X[16]
(及以后)时,您正在调用未定义的行为(任何事情都可能发生)。
我认为你实际上并不是说你分配给X[32]
。您的意思可能是 &X[32]
与 &Z[0]
相同。如果真是这样,那就没有什么特别有趣的了:数组在内存中一个接一个地布局。
0x000000008304ed6a in ?? ()
这通常意味着堆栈损坏(某些东西覆盖了 return 地址,而您 return 陷入了困境)。假设 X
是一个 local 数组,越界写入它极有可能导致这种损坏。
查找此类堆栈损坏的一种简单方法是使用 Address Sanitizer(适用于 Clang 和 GCC)。
更新:
Address Sanitizer 错误告诉您
- 在
TMV_multiplication()
中,您有一个 32 字节的本地数组 VecA
(可能 int VecA[8];
)和
- 您越界访问(读取)该数组(尝试访问刚好超过该数组末尾的偏移量 320)。
此错误不是导致崩溃的原因。您应该修复它,然后重新运行。在这个之后有更多的错误。全部修复后,您的程序将不再崩溃。
感谢 address sanitizer 的输出,但为什么删除了源?
无论如何,如果我没记错的话,输出会告诉你 VecA[8]
中有一个访问超出范围。
这个问题是我上一个问题的 sequel,目前的状态是我已经获得了地址清理器的输出——@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 之前指出的那样,问题很可能出在堆栈上。现在,如何解决这个堆栈问题?因为这些都在我头上。
I have three unsigned int arrays
X[16], Y[16], Z[16]
in themain
...
X[32]=Z[0]
你可以就在这里。
访问 X
的有效索引是 0 到 15。当您访问 X[16]
(及以后)时,您正在调用未定义的行为(任何事情都可能发生)。
我认为你实际上并不是说你分配给X[32]
。您的意思可能是 &X[32]
与 &Z[0]
相同。如果真是这样,那就没有什么特别有趣的了:数组在内存中一个接一个地布局。
0x000000008304ed6a in ?? ()
这通常意味着堆栈损坏(某些东西覆盖了 return 地址,而您 return 陷入了困境)。假设 X
是一个 local 数组,越界写入它极有可能导致这种损坏。
查找此类堆栈损坏的一种简单方法是使用 Address Sanitizer(适用于 Clang 和 GCC)。
更新:
Address Sanitizer 错误告诉您
- 在
TMV_multiplication()
中,您有一个 32 字节的本地数组VecA
(可能int VecA[8];
)和 - 您越界访问(读取)该数组(尝试访问刚好超过该数组末尾的偏移量 320)。
此错误不是导致崩溃的原因。您应该修复它,然后重新运行。在这个之后有更多的错误。全部修复后,您的程序将不再崩溃。
感谢 address sanitizer 的输出,但为什么删除了源?
无论如何,如果我没记错的话,输出会告诉你 VecA[8]
中有一个访问超出范围。