[Lldb-commits] [PATCH] D109937: [lldb] Handle malformed qfThreadInfo reply

Ted Woodward via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 16 16:41:10 PDT 2021


ted created this revision.
ted added a reviewer: clayborg.
ted requested review of this revision.
Herald added a project: LLDB.

If the remote gdbserver's qfThreadInfo reply has a trailing comma,
GDBRemoteCommunicationClient::GetCurrentProcessAndThreadIDs will return
an empty vector of thread ids. This will cause lldb to recurse through
three functions trying to get the list of threads, until it blows its
stack and crashes.

A trailing comma is a malformed response, but it shouldn't cause lldb to
crash. This patch will return the tids received before the malformed
response.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109937

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2906,8 +2906,13 @@
       if (ch == 'm') {
         do {
           auto pid_tid = response.GetPidTid(LLDB_INVALID_PROCESS_ID);
-          if (!pid_tid)
-            return {};
+          if (!pid_tid) {
+            // if ids is empty, this is an error
+            if (ids.size() == 0)
+              return {};
+            // if ids is not empty, bail out from here and process ids
+            break;
+          }
 
           ids.push_back(pid_tid.getValue());
           ch = response.GetChar(); // Skip the command separator


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109937.373104.patch
Type: text/x-patch
Size: 836 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210916/11f7fc9f/attachment.bin>


More information about the lldb-commits mailing list