Whi*_*Kew 5 seh buffer-overrun
我们有一些 C 代码偶尔会抛出STATUS_STACK_BUFFER_OVERRUN错误 ( )。0xC0000409我可以使用下面的 C 代码重现该错误。我在 Windows 7 上使用 Visual Studio 2013 Update 4,并使用/EHa和/GS标志进行编译。但是,我无法以编程方式捕获错误。代码永远不会进入我的__except块;相反,Visual Studio 会弹出几个对话框,通知我堆栈损坏。我意识到,一旦出现这个错误,程序的状态就受到怀疑;我只是试图捕获错误,希望找到它在我们的生产代码中发生的位置。有没有办法以编程方式处理这个错误?
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#pragma warning(disable: 4996) // strcpy
void vulnerable(const char* str)
{
char buffer[10];
strcpy(buffer, str); // overrun the buffer
}
int main()
{
__try
{
char large_buffer[] = "This string is longer than 10 characters.";
vulnerable(large_buffer);
}
__except (GetExceptionCode() == STATUS_STACK_BUFFER_OVERRUN)
{
printf("error"); // never getting here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1947 次 |
| 最近记录: |