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
This commit is contained in:
Adrian Prantl 2019-06-11 21:14:02 +00:00
parent 4c3722aea8
commit e6130a3090
3 changed files with 9 additions and 0 deletions

View File

@ -0,0 +1 @@
process attach --pid

View File

@ -0,0 +1,2 @@
# RUN: %lldb -x -b -S %S/Inputs/process_attach_pid.in 2>&1 | FileCheck %s
# CHECK: requires an argument

View File

@ -1362,6 +1362,12 @@ llvm::Expected<Args> Options::Parse(const Args &args,
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;