Skip to content

Commit e6130a3

Browse files
committed
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 llvm-svn: 363101
1 parent 4c3722a commit e6130a3

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process attach --pid
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# RUN: %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s
2+
# CHECK: requires an argument

lldb/source/Interpreter/Options.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,12 @@ llvm::Expected<Args> Options::Parse(const Args &args,
13621362
int long_options_index = -1;
13631363
val = OptionParser::Parse(argv.size(), &*argv.begin(), sstr.GetString(),
13641364
long_options, &long_options_index);
1365+
1366+
if ((size_t)OptionParser::GetOptionIndex() > argv.size()) {
1367+
error.SetErrorStringWithFormat("option requires an argument");
1368+
break;
1369+
}
1370+
13651371
if (val == -1)
13661372
break;
13671373

0 commit comments

Comments
 (0)