aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormmentovai <mmentovai@4c0a9323-5329-0410-9bdc-e9ce6186880e>2008-12-03 17:21:34 +0000
committermmentovai <mmentovai@4c0a9323-5329-0410-9bdc-e9ce6186880e>2008-12-03 17:21:34 +0000
commite5c401467b09f4e19aa79805863adfaf64a8a972 (patch)
treef0656ddeaed947264e2868523f0d874441e2d07c /src
parentfollow up for issue 281 - dump_syms fails to find dylib symbol file inside of... (diff)
downloadbreakpad-e5c401467b09f4e19aa79805863adfaf64a8a972.tar.xz
ExceptionHandler class is not handling initialization errors, such as the
handler thread not being created. Protect the exception handler against failure to create semaphores and a thread handle. Patch by Marc-André (MAD) Decoste, r=me http://code.google.com/p/google-breakpad/issues/detail?id=285 http://codereview.chromium.org/13065 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@300 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src')
-rw-r--r--src/client/windows/handler/exception_handler.cc36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/client/windows/handler/exception_handler.cc b/src/client/windows/handler/exception_handler.cc
index 8594d1bf..7217e19d 100644
--- a/src/client/windows/handler/exception_handler.cc
+++ b/src/client/windows/handler/exception_handler.cc
@@ -140,15 +140,22 @@ void ExceptionHandler::Initialize(const wstring& dump_path,
// context outside of an exception.
InitializeCriticalSection(&handler_critical_section_);
handler_start_semaphore_ = CreateSemaphore(NULL, 0, 1, NULL);
- handler_finish_semaphore_ = CreateSemaphore(NULL, 0, 1, NULL);
+ assert(handler_start_semaphore_ != NULL);
- DWORD thread_id;
- handler_thread_ = CreateThread(NULL, // lpThreadAttributes
- kExceptionHandlerThreadInitialStackSize,
- ExceptionHandlerThreadMain,
- this, // lpParameter
- 0, // dwCreationFlags
- &thread_id);
+ handler_finish_semaphore_ = CreateSemaphore(NULL, 0, 1, NULL);
+ assert(handler_finish_semaphore_ != NULL);
+
+ // Don't attempt to create the thread if we could not create the semaphores.
+ if (handler_finish_semaphore_ != NULL && handler_start_semaphore_ != NULL) {
+ DWORD thread_id;
+ handler_thread_ = CreateThread(NULL, // lpThreadAttributes
+ kExceptionHandlerThreadInitialStackSize,
+ ExceptionHandlerThreadMain,
+ this, // lpParameter
+ 0, // dwCreationFlags
+ &thread_id);
+ assert(handler_thread_ != NULL);
+ }
dbghelp_module_ = LoadLibrary(L"dbghelp.dll");
if (dbghelp_module_) {
@@ -264,6 +271,8 @@ ExceptionHandler::~ExceptionHandler() {
DWORD ExceptionHandler::ExceptionHandlerThreadMain(void* lpParameter) {
ExceptionHandler* self = reinterpret_cast<ExceptionHandler *>(lpParameter);
assert(self);
+ assert(self->handler_start_semaphore_ != NULL);
+ assert(self->handler_finish_semaphore_ != NULL);
while (true) {
if (WaitForSingleObject(self->handler_start_semaphore_, INFINITE) ==
@@ -519,6 +528,17 @@ bool ExceptionHandler::WriteMinidumpOnHandlerThread(
EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion) {
EnterCriticalSection(&handler_critical_section_);
+ // There isn't much we can do if the handler thread
+ // was not successfully created.
+ if (handler_thread_ == NULL) {
+ LeaveCriticalSection(&handler_critical_section_);
+ return false;
+ }
+
+ // The handler thread should only be created when the semaphores are valid.
+ assert(handler_start_semaphore_ != NULL);
+ assert(handler_finish_semaphore_ != NULL);
+
// Set up data to be passed in to the handler thread.
requesting_thread_id_ = GetCurrentThreadId();
exception_info_ = exinfo;