类成员重叠全局变量

时间:2016-11-03 08:36:46

标签: gcc memory overlap address-sanitizer

我正在处理我的应用程序的不良行为...... 我最近将我的g ++ - 4.1升级为g ++ - 4.8,并且我遇到了某些类实例的私有成员与主要源中全局定义的一些变量之间的内存重叠。

使用gdb捕获写入并查看变量指针我可以看到它们共享相同的内存地址。

激活4.8中引入的-fsanitize =地址我可以看到相同的内容。


=================================================================
==5160== ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000079750c at pc 0x4ba54f bp 0x7ffc0dc35df0 sp 0x7ffc0dc35de8
WRITE of size 1 at 0x00000079750c thread T0
    #0 0x4ba54e (/opt/softplc/softplc+0x4ba54e)
    #1 0x4bd988 (/opt/softplc/softplc+0x4bd988)
    #2 0x4c1ea1 (/opt/softplc/softplc+0x4c1ea1)
    #3 0x4ba7c5 (/opt/softplc/softplc+0x4ba7c5)
    #4 0x409116 (/opt/softplc/softplc+0x409116)
    #5 0x511cfc (/opt/softplc/softplc+0x511cfc)
    #6 0x7fce6124de54 (/lib/x86_64-linux-gnu/libc-2.19.so+0x21e54)
    #7 0x409c24 (/opt/softplc/softplc+0x409c24)
0x00000079750c is located 20 bytes to the left of global variable 'loopcounteryyyyyyy (softplc.cpp)' (0x797520) of size 8
  'loopcounteryyyyyyy (softplc.cpp)' is ascii string ''
0x00000079750c is located 36 bytes to the right of global variable 'tod (softplc.cpp)' (0x7974e0) of size 8
  'tod (softplc.cpp)' is ascii string ''
Shadow bytes around the buggy address:
  0x0000800eae50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800eae60: 00 00 logger thread PID= 5160
 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800eae70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800eae80: 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0000800eae90: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
=>0x0000800eaea0: f9[f9]f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0000800eaeb0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0000800eaec0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0000800eaed0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0000800eaee0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x0000800eaef0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
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
==5160== ABORTING

代码非常庞大,当我尝试切割部分代码以隔离问题时,重叠区域向上移动消失。

无论如何,一切都是静态定义的,没有实例定义的运行时因此,我认为,重叠是编译器或gcclib的一种错误,或者我不知道还有谁分配了两个不同的同一地址的项目。 问题是:我可以通过其他方式调查和生成更多有用的信息,以便跟踪这个问题的原因" bug" ?

0 个答案:

没有答案