Don't crash when given an empty input filename. (#184718)
Commands such as `clang -- ''` hit two different crash bugs: a buffer overflow caused by using a `memcmp` that might be larger than the input, and a bogus assert in the option parser when attempting typo correction.
This commit is contained in:
parent
add7b711de
commit
6ae0e6d5fb
@ -3082,7 +3082,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
|
||||
InputTypeArg->claim();
|
||||
|
||||
// stdin must be handled specially.
|
||||
if (memcmp(Value, "-", 2) == 0) {
|
||||
if (strcmp(Value, "-") == 0) {
|
||||
if (IsFlangMode()) {
|
||||
Ty = types::TY_Fortran;
|
||||
} else if (IsDXCMode()) {
|
||||
|
||||
2
clang/test/Driver/empty_arg.c
Normal file
2
clang/test/Driver/empty_arg.c
Normal file
@ -0,0 +1,2 @@
|
||||
// RUN: not %clang -- "" 2>&1 | FileCheck %s
|
||||
// CHECK: error: no such file or directory: ''
|
||||
@ -264,8 +264,6 @@ unsigned OptTable::internalFindNearest(
|
||||
StringRef Option, std::string &NearestString, unsigned MinimumLength,
|
||||
unsigned MaximumDistance,
|
||||
std::function<bool(const Info &)> ExcludeOption) const {
|
||||
assert(!Option.empty());
|
||||
|
||||
// Consider each [option prefix + option name] pair as a candidate, finding
|
||||
// the closest match.
|
||||
unsigned BestDistance =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user