[PATCH] D42868: Fix a crash in *NetBSD::Factory::Launch

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 14:11:07 PST 2018


krytarowski created this revision.
krytarowski added reviewers: labath, joerg.
Herald added a subscriber: llvm-commits.
krytarowski edited the summary of this revision.

We cannot call process_up->SetState() inside
the NativeProcessNetBSD::Factory::Launch
function because it triggers a NULL pointer
deference.

The generic code for launching a process in:
GDBRemoteCommunicationServerLLGS::LaunchProcess
sets the m_debugged_process_up pointer after
a successful call to  m_process_factory.Launch().
If we attempt to call process_up->SetState()
inside a platform specific Launch function we
end up dereferencing a NULL pointer in
NativeProcessProtocol::GetCurrentThreadID().

Follow the Linux case and move SetState() to:
NativeProcessNetBSD::NativeProcessNetBSD.

Sponsored by <The NetBSD Foundation>


Repository:
  rL LLVM

https://reviews.llvm.org/D42868

Files:
  source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp


Index: source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
===================================================================
--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -113,7 +113,6 @@
 
   for (const auto &thread : process_up->m_threads)
     static_cast<NativeThreadNetBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
-  process_up->SetState(StateType::eStateStopped);
 
   return std::move(process_up);
 }
@@ -160,6 +159,8 @@
   m_sigchld_handle = mainloop.RegisterSignal(
       SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
   assert(m_sigchld_handle && status.Success());
+
+  SetState(StateType::eStateStopped, false);
 }
 
 // Handles all waitpid events from the inferior process.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42868.132678.patch
Type: text/x-patch
Size: 783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180202/c1c26ca5/attachment.bin>


More information about the llvm-commits mailing list