使用智能卡签名(C++)时为RtlFreeHeap指定的地址无效

Invalid Address specified to RtlFreeHeap When use Smart Card to Sign (C++)

本文关键字:RtlFreeHeap 无效 地址 时为 智能卡 C++      更新时间:2023-10-16
  • 我使用的是C++和Visual Studio 2010

当我使用智能卡执行签名时,会出现:"当程序完成时。">

Windows has triggered a breakpoint in MyProgram.exe.
This may be due to a corruption of the heap, and indicates a bug in MyProgram.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information

输出

HEAP[MyProgram.exe]: Invalid Address specified to RtlFreeHeap( 003C0000, 01BBFEA0 )
Windows has triggered a breakpoint in MyProgram.exe.
This may be due to a corruption of the heap, which indicates a bug in MyProgram.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while MyProgram.exe has focus.
The output window may have more diagnostic information.

MyProgram.exe程序使用dll"signer.dll">

我尝试使用"无智能卡"进行签名。仅使用Windows证书。OK正常终止
我尝试使用智能卡进行签名,出现一个窗口询问PIN。程序结束时。错误-为RtlFreeHeap指定的地址无效
我使用智能卡,当它要求输入PIN时,我会标记为"NOT"。当程序结束时。错误-为RtlFreeHeap指定的地址无效。

我注意到只有当出现要求输入PIN的窗口时才会出现错误。

因此,我尝试使用WinDbg,遵循这篇文章:http://www.codeproject.com/KB/debug/windbg_quick_start.aspx

我把断点放在"CryptSignMessage"出现:"当使用智能卡时">

(150c.17fc): C++ EH exception - code e06d7363 (first chance)
(150c.17fc): C++ EH exception - code e06d7363 (first chance)

当没有使用智能卡时,不会发生这种情况。

我认为他试图了解钥匙的上下文,但做不到,而且"破坏了记忆"。在"第一次机会"后提示PIN的窗口。

这是问题所在吗?如何在使用CryptSignMessage之前获取带有密钥上下文的证书?

我该如何修复?

没有智能卡,我可以正常签名。使用智能卡,我可以正常签名,但当程序完成时,出现错误。

智能卡上的标志应该注意什么?

提前感谢

正如消息所示,这似乎是堆损坏。他们不太容易找到。你最好的办法是使用内存分析工具来帮助找到原因。