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
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
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits