[Lldb-commits] [PATCH] D63110: Fix a crash in option parsing.

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 10 16:59:11 PDT 2019


aprantl created this revision.
aprantl added a reviewer: JDevlieghere.
Herald added a project: LLDB.

The call to getopt_long didn't handle the case where the *last* option had an argument missing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63110

Files:
  lldb/lit/Driver/Inputs/process_attach_pid.in
  lldb/lit/Driver/TestProcessAttach.test
  lldb/source/Interpreter/Options.cpp


Index: lldb/source/Interpreter/Options.cpp
===================================================================
--- lldb/source/Interpreter/Options.cpp
+++ lldb/source/Interpreter/Options.cpp
@@ -1362,6 +1362,12 @@
     int long_options_index = -1;
     val = OptionParser::Parse(argv.size(), &*argv.begin(), sstr.GetString(),
                               long_options, &long_options_index);
+
+    if ((size_t)OptionParser::GetOptionIndex() > argv.size()) {
+      error.SetErrorStringWithFormat("option requires an argument");
+      break;
+    }
+
     if (val == -1)
       break;
 
Index: lldb/lit/Driver/TestProcessAttach.test
===================================================================
--- /dev/null
+++ lldb/lit/Driver/TestProcessAttach.test
@@ -0,0 +1,2 @@
+# RUN: %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s
+# CHECK: requires an argument
Index: lldb/lit/Driver/Inputs/process_attach_pid.in
===================================================================
--- /dev/null
+++ lldb/lit/Driver/Inputs/process_attach_pid.in
@@ -0,0 +1 @@
+process attach --pid


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63110.203940.patch
Type: text/x-patch
Size: 1101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190610/15a54d66/attachment.bin>


More information about the lldb-commits mailing list