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:
Richard Smith 2026-03-05 12:50:03 -08:00 committed by GitHub
parent add7b711de
commit 6ae0e6d5fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View File

@ -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()) {

View File

@ -0,0 +1,2 @@
// RUN: not %clang -- "" 2>&1 | FileCheck %s
// CHECK: error: no such file or directory: ''

View File

@ -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 =