Author: Richard Smith Date: 2026-03-05T12:50:03-08:00 New Revision: 6ae0e6d5fb2cff91f9aef9b19adbc144fe8d20ff
URL: https://github.com/llvm/llvm-project/commit/6ae0e6d5fb2cff91f9aef9b19adbc144fe8d20ff DIFF: https://github.com/llvm/llvm-project/commit/6ae0e6d5fb2cff91f9aef9b19adbc144fe8d20ff.diff LOG: 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. Added: clang/test/Driver/empty_arg.c Modified: clang/lib/Driver/Driver.cpp llvm/lib/Option/OptTable.cpp Removed: ################################################################################ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index afa1884d94b70..420340aaab885 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -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()) { diff --git a/clang/test/Driver/empty_arg.c b/clang/test/Driver/empty_arg.c new file mode 100644 index 0000000000000..94ed8f13cbec4 --- /dev/null +++ b/clang/test/Driver/empty_arg.c @@ -0,0 +1,2 @@ +// RUN: not %clang -- "" 2>&1 | FileCheck %s +// CHECK: error: no such file or directory: '' diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index 065036cedc2ae..8444675b847e6 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -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 = _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
