开发者

Catching child process exceptions on windows

开发者 https://www.devze.com 2023-01-28 03:37 出处:网络
i\'m developing a multi-platform C++ fuzzing application. The app spawns a child process and checks whether it stopped unexpectedly. I\'ve already managed to do this on linux, however, windows excepti

i'm developing a multi-platform C++ fuzzing application. The app spawns a child process and checks whether it stopped unexpectedly. I've already managed to do this on linux, however, windows exception handling mechanism is making things hard for me.

My code right now does the following: - Call Create开发者_如何学GoProcess to spawn the process. - WaitForSingleObject to wait for it to terminate. - Then call GetExitCodeProcess and check if the exit code corresponds to an exception.

Everything works as it should, i've tested it with a null dereferencing test application, and i can catch the exception gracefully. However, each time i test this, a Windows error message box spawns telling me to Send or Not Send the error report. Since the fuzzer is supposed to be an automatic testing application, i'd need to somehow disable this notification, so that even if an exception is caught, the fuzzer can continue testing.

I've already tried installing a SEH handler, but had no luck(apparently these handlers aren't inherited by child processes). I've read something about using vectored exception handling, but suppose it would be the same, i believe vector handlers aren't inherited.

Could anybody help me with this problem? I don't know what to search for, i've already googled a lot and haven't found anyhing.

Thanks!


Debug API is one option. Here is a starting point in MSDN.


Following on frast's answer, you can spawn the process as a child of a process with a suitable SetErrorMode. This (inheritable) setting determines which errors will result in dialogs popping out - I found your question while trying to achieve the exact same thing for an automated testing application.

To avoid any error dialogs, use

SetErrorMode(
    SEM_FAILCRITICALERRORS 
    | SEM_NOALIGNMENTFAULTEXCEPT 
    | SEM_NOGPFAULTERRORBOX 
    | SEM_NOOPENFILEERRORBOX);

Injection is probably overkill - better to use a wrapper process.


Try to inject the following code into your child process:

SetErrorMode(SEM_NOGPFAULTERRORBOX);

Lookup the details of SetErrorMode in MSDN.

Read about injection technique here: Injective Code inside Import Table

0

精彩评论

暂无评论...
验证码 换一张
取 消