Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1214|回复: 4
打印 上一主题 下一主题

堆破坏

[复制链接]

1228

主题

1997

帖子

7582

积分

认证用户组

Rank: 5Rank: 5

积分
7582
跳转到指定楼层
楼主
发表于 2019-12-31 10:20:37 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Qter 于 2019-12-31 10:25 编辑

“iLAP_summary_cdma.exe”: 已加载“E:\svn\ilap_summary\branches\kk\cdma_summary\dist\Win32\Debug\iLAP_summary\bin\iLAP_summary_cdma.exe”,已加载符号。
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\ntdll.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\kernel32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\ws2_32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\advapi32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\rpcrt4.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\secur32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\msvcrt.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\ws2help.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oci.dll”,未使用调试信息生成二进制文件。
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\msvcr71.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“E:\svn\ilap_summary\branches\kk\cdma_summary\dist\Win32\Debug\iLAP_summary\bin\CommonCDMA.dll”,已加载符号。
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\msvcp100d.dll”,已加载符号。
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\msvcr100d.dll”,已加载符号。
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\shimeng.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已卸载“C:\WINDOWS\system32\shimeng.dll”
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oraclient10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oracore10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oranls10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oraunls10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orauts.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\user32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\gdi32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\winmm.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\ole32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oravsn10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oracommon10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orageneric10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orasnls10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oraxml10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\msvcirt.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oran10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oranl10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oranldap10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orannzsbb10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oraldapclnt10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orancrypt10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\wsock32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\oleaut32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oranro10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oranhost10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orancds10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orantns10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orapls10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\ORASLAX10.DLL”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oraplp10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orahasgen10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oraocr10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\oraocrb10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\netapi32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\psapi.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orantcp10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“D:\oracle\product\10.2.0\client_1\BIN\orasql10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\imm32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\lpk.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\usp10.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\Program Files\Common Files\Thunder Network\NetMon\net_monitor2.0.2.6.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\shell32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\shlwapi.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\MSVCP71.DLL”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\version.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\comctl32.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\mswsock.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\hnetcfg.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\wshtcpip.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\uxtheme.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\Program Files\360\360Safe\safemon\safemon.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\wininet.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\normaliz.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\urlmon.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\iertutil.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\MSCTF.dll”,Cannot find or open the PDB file
“iLAP_summary_cdma.exe”: 已加载“C:\WINDOWS\system32\apphelp.dll”,Cannot find or open the PDB file
线程 'Win32 线程' (0x444) 已退出,返回值为 0 (0x0)。
HEAP[iLAP_summary_cdma.exe]: HEAP: Free Heap block 19465738 modified at 194657f4 after it was freed
Windows 已在 iLAP_summary_cdma.exe 中触发一个断点。

其原因可能是堆被损坏,这说明 iLAP_summary_cdma.exe 中或它所加载的任何 DLL 中有 Bug。

原因也可能是用户在 iLAP_summary_cdma.exe 具有焦点时按下了 F12。

输出窗口可能提供了更多诊断信息。



堆调试工具——pageheap的使用和原理分析.docx (24.76 KB, 下载次数: 0)

回复

使用道具 举报

1228

主题

1997

帖子

7582

积分

认证用户组

Rank: 5Rank: 5

积分
7582
沙发
 楼主| 发表于 2019-12-31 10:20:53 | 只看该作者
本帖最后由 Qter 于 2019-12-31 10:21 编辑

cd和fd:        调试模式下堆上未初始化的内存为cd,并且在内存结束处有4个fd的边界,用于debug模式下crt做内存检查


http://support.microsoft.com/kb/286470/zh-cn
回复 支持 反对

使用道具 举报

1228

主题

1997

帖子

7582

积分

认证用户组

Rank: 5Rank: 5

积分
7582
板凳
 楼主| 发表于 2019-12-31 10:22:23 | 只看该作者
Pageheap.exe
下面我们简单地给出PageHeap使用步骤:
  第一步:
  在命令行中运行PageHeap.Exe。如果你以前设置过启用Global Page Heap标志,那么你将看到一个列表,给出所有已经启用了的应用程序的名字,不含路径。
  如下所示:
  C:\>pageheap
  pgh.exe enabled
  testSplit.exe enabled
  第二步:
  编译一个小程序,其中有如下代码:
  void main()
  {
   int m_len = 5;
   char *m_p = (char *)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, m_len);
   m_p[m_len] = 0;
  
   HeapFree (GetProcessHeap (),0, m_p);
  }
  Build出一个Debug版本。运行之,你看不到有任何异常的报告。
  但其实m_p[m_len]=0这句话就是越界写了,因为只分配到了m_p[m_len-1]!这种情况就叫Dynamic memory overrun。用BoundsChecker是可以查到的。
  这时,表面上看不出任何问题,但是一颗定时炸弹已经埋下了。
  第三步:
  在命令行中运行PageHeap /enable YourApplicationName.exe 0x01。
  再运行一次不带参数的PageHeap,察看上面的命令是否生效。你的应用程序应该在启用的列表中。
  注意:千万不要在YourApplication.Exe前面加上路径!!
  0x01的含义在后面说明。
  第四步:
  再次运行你的程序。
  你将会注意到在Output窗口的加载各种DLL之前,多了几句话:
  Loaded exports for 'C:\WINNT\System32\ntdll.dll'
  Page heap: process 0x57C created heap @ 00130000 (00230000, flags 0x1)
  Loaded 'C:\WINNT\system32\MFC42D.DLL', no matching symbolic information found.
  ..
  Loaded 'C:\WINNT\system32\MSVCP60D.DLL', no matching symbolic information found.
  Page heap: process 0x57C created heap @ 00470000 (00570000, flags 0x1)
  Loaded exports for 'C:\WINNT\system32\imm32.dll'
  这就是Page Heap的监视机制在发挥作用!他告诉你你的堆00470000被创建出来了。
  然后程序退出后,Output窗口有这么几句话表明一定有什么错误发生了:
  Page heap: block @ 0015AFF8 is corrupted (reason 10)
  Page heap: reason: corrupted suffix pattern
  Page heap: process 0x57C destroyed heap @ 00471000 (00570000)
  The thread 0x8A8 has exited with code 0 (0x0).
  这说明在销毁堆00470000时遇到了麻烦,就是数据块0015AFF8被误用了,原因是误用了下标语法。看,说得多么清楚!也节省了许多翻来覆去查代码的工作!
  PageHeap的使用中有几点值得注意:
  1:启用PageHeap不能够影响正在运行中的应用程序。如果你需要启用一些正在运行且不能重启的程序的PageHeap,那请运行PageHeap启用后,重新启动机器。
  2:要想查看PageHeap把信息放到哪里了,请打开你的注册表,来到
   \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT
  \CurrentVersion\Image File Execution Options
  你将会看到你的应用程序也在这个项下面。你的应用程序的GlobalFlag被设置为了0x02000000,PageHeapFlags被设置为了0x01。
  3:PageHeap的原理是这样,它在已分配的内存的后面放上几个守护字节(Guard Bytes),再跟上一个标记为PAGE_NOACCESS的内存页。这样,已分配内存的后面如果被重写了,那么守护字节就会被改变,于是当内存被释放时,PageHeap就会引发一个AV(Access Violation)。大体上就是这样。所以只有最后释放这块问题内存时,才会有PageHeap的报告!这就是PageHeap的局限性吧。
  参数0x01的含义:
  FLAGS hex value (0x...) has the following structure:
   B7-B0 Bit flags 1 - enable page heap
   01 - enable page heap. If zero normal heap is used.
   In 99% of the cases you will want this to be set.
   02 - collect stack traces (default on checked builds)
   04 - minimize memory impact
   08 - minimize randomly(1)/based on size range(0)
   10 - catch backward overruns
  看到了吗?你还可以设置参数为0x10,从而可以检查内存向前的越界写!
  Gflags.Exe是微软的Debugging Tools里面的工具。在Windows 2000的Resource Kit中也可以找得到。我们也可以用它来完成和PageHeap相同的任务。当然,Gflags.EXE还能做许许多多其他的事情。这里我们就不介绍了,总之物超所值。
  具体的使用办法是:
  1) 运行Gflags.Exe;
  2) 你将看到一个对话框。在”Image File”的编辑框中写下你的应用程序的名字,如YourApp.Exe。注意不要路径!
  3) 选择”Image File Options”的单选钮;
  4) 这时,你会看到对话框的内容突然一变。选中“Place heap
  allocations at ends of pages”前的复选框。
  5) 点击Apply按钮。
  这样,就达到了PageHeap的效果。现在运行你的程序,overwrite你的堆,就应该生成一个AV了!
  (预知详情请收听微软KB:SAMPLE: PageHeap1.exe Finds Heap Corruption and Memory Errors (Q264471) 你可以按照这篇文档所指引的步骤学习如何使用PageHeap)
  (To be Continued)
回复 支持 反对

使用道具 举报

1228

主题

1997

帖子

7582

积分

认证用户组

Rank: 5Rank: 5

积分
7582
地板
 楼主| 发表于 2019-12-31 10:22:54 | 只看该作者
问题分析:
根据vs的输出,确定问题是在一块堆上分配的内存在释放后被改写了。由于CRT只能在下次做堆操作检查时才会暴露出问题,所以程序崩溃的调用栈是不确定的。
折腾了2个小时后,启用pageheap缩小了程序出错到崩溃之间的距离,解决了问题。过程如下:
1:启动pageheap
pageheap /enable mybug.exe 0x01
2:调试启动mybug.exe
现在程序崩溃的调用栈每次都相同,并且都在相同的线程中,根据调用栈信息很轻松的锁定了bug。




1.dll与exe相互调用问题
http://yaogangshi.iteye.com/blog/1001690
当时就觉得非常奇怪。到网上搜索了crtheap就有预感可能是crtheap的问题。
后来就搜到了微软的这篇文章,dll间传递CRT对象(文件句柄、环境变量、区域信息等)存在潜在问题。
进程分配内存(显式调用new,allocate,隐式分配内存比如调用strdup,strstreambuf::str等)
然后传递给DLL进行释放。都可能因为使用了不同的CRT库造成内存非法访问和栈破坏。
每一份CRT库的都有独立和唯一一份状态,并且每一份CRT库都有自己的对管理器。DLL和EXE可能使用了不同的CRT库,所以分配和释放内存的堆不能匹配从而导致了堆破坏。
修复方法:
EXE和所有的DLL都必须动态链接/MD到同一份CRT。

2.
原来是把一个类指针强转为另一个子类的指针,调用了子类的一个函数,但是该类不存在这个函数.同时这个子类函数里面做了一次bool变量赋值,结果这个值就写到了堆地址里面去了.

3.数组越界
  1. int ACC_ACTSET_NUM[6];

  2.         if (nActsetCount > 0 && nActsetCount <=6) //加上了nActsetCount > 0
  3.         {
  4.                 kpi_cover.ACC_ACTSET_NUM[nActsetCount-1] +=1;
  5.         }

  6.                 if (nDuration > 0 && nDuration % 10 == 0)
  7.                 {
  8.                         --index;
  9.                 }
  10.                 if (index >= 0 && index < 6)
  11.                 {
  12.                         kpi_duration.DATA_DURATION_0_60_NUM[index] +=1;
  13.                 }
  14. void KpiDoAlgorithm::Duration_count(int * DURATION,int call_duration)
  15. {
  16.         if ( call_duration < 0 || call_duration > 60 )
  17.         {
  18.                 return;
  19.         }
  20.         int index =0;
  21.         index =  call_duration / 10  ;
  22.         if(call_duration > 0 && (call_duration % 10 == 0))
  23.         {
  24.                 --index;
  25.         }
  26.         DURATION[index] +=1;
  27. }
复制代码
回复 支持 反对

使用道具 举报

1228

主题

1997

帖子

7582

积分

认证用户组

Rank: 5Rank: 5

积分
7582
5#
 楼主| 发表于 2019-12-31 10:23:56 | 只看该作者
过程是这样的,在vc debug的过程中,突然弹出了一个assert窗口:



Windows has triggered a breakpoint in cs.exe.

This may be due to a corruption of the heap, which indicates a bug in cs.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while cs.exe has focus.



查看output输出:

Heap missing last entry in committed range near e664630

Windows has triggered a breakpoint in cs.exe.



This may be due to a corruption of the heap, which indicates a bug in cs.exe or any of the DLLs it has loaded.



不废话,直接查看该内存是什么:

0x0E664630  0e 00 0f 00 59 03 10 04 aa aa cd ab 00 10 72 85 38 00

看不出什么,往上再看看:

0x0E66460C  07 e2 04 00 a8 01 66 0e 01 00 cd cd fd fd fd fd....



看来这就是块堆内存,实在看不出什么,决定暂时忽略. 过了几天,该错误没有再出现过.



但就在交付程序前一天测试中,又出现了这个错误.看来一颗定时炸弹是埋藏在了程序中.必须找出来,否则后果很严重.



首先要做的就是要重现这个问题,如果每次碰巧遇到这个问题的话,实在无从下手.从症状来看,是个典型的Heap Corrupt.所以先使用工具:pageheap,以做到能够百分百重现那个堆破坏.



page heap工具启用的两种方法:Full-page heap和Normal page heap

我先使用了Normal page heap 命令为pageheap /enable xx.exe /normal



然后通过windbg设置符号表:x:/symbols_folder;srv*x:/symbols_folder*http://msdl.microsoft.com/download/symbols



开始各种调试,几乎用遍了<<Windows高级调试>>这本书中指导的各种命令,(调试过程省略2000字)未果.几乎崩溃时,突然看到书上的这么一段话:



普通页堆通过填充模式检测堆块破坏,需要再发生堆破坏之后再调用一次堆管理器.

完全页堆除了特定的填充模式外,它还为每个堆块增加了防护页,防护页是一个页不可访问的内存,它被放置在堆块的起始位置和结束位置上.防止堆块上下溢出.



我靠,直接pageheap /enable xx.exe /full 设置完全页堆模式.重新运行程序.

瞬间程序崩掉,这个激动呀.还是第一次看见程序崩掉那么激动,查看崩溃的代码:

原来是把一个类指针强转为另一个子类的指针,调用了子类的一个函数,但是该类不存在这个函数.同时这个子类函数里面做了一次bool变量赋值,结果这个值就写到了堆地址里面去了.



总结

以后遇到类似问题,直接pageheap full 全开.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-2 09:36 , Processed in 0.065185 second(s), 21 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表