[Lldb-commits] [lldb] r363101 - Fix a crash in option parsing.

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 11 14:14:02 PDT 2019


Author: adrian
Date: Tue Jun 11 14:14:02 2019
New Revision: 363101

URL: http://llvm.org/viewvc/llvm-project?rev=363101&view=rev
Log:
Fix a crash in option parsing.

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

<rdar://problem/51231882>

Differential Revision: https://reviews.llvm.org/D63110

Added:
    lldb/trunk/lit/Driver/Inputs/process_attach_pid.in
    lldb/trunk/lit/Driver/TestProcessAttach.test
Modified:
    lldb/trunk/source/Interpreter/Options.cpp

Added: lldb/trunk/lit/Driver/Inputs/process_attach_pid.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Driver/Inputs/process_attach_pid.in?rev=363101&view=auto
==============================================================================
--- lldb/trunk/lit/Driver/Inputs/process_attach_pid.in (added)
+++ lldb/trunk/lit/Driver/Inputs/process_attach_pid.in Tue Jun 11 14:14:02 2019
@@ -0,0 +1 @@
+process attach --pid

Added: lldb/trunk/lit/Driver/TestProcessAttach.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Driver/TestProcessAttach.test?rev=363101&view=auto
==============================================================================
--- lldb/trunk/lit/Driver/TestProcessAttach.test (added)
+++ lldb/trunk/lit/Driver/TestProcessAttach.test Tue Jun 11 14:14:02 2019
@@ -0,0 +1,2 @@
+# RUN: %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s
+# CHECK: requires an argument

Modified: lldb/trunk/source/Interpreter/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Options.cpp?rev=363101&r1=363100&r2=363101&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Options.cpp (original)
+++ lldb/trunk/source/Interpreter/Options.cpp Tue Jun 11 14:14:02 2019
@@ -1362,6 +1362,12 @@ llvm::Expected<Args> Options::Parse(cons
     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;
 




More information about the lldb-commits mailing list