Merge pull request #4190 from ArchitDewan/fix/relinker-empty-path

fix(relinker): reject empty positional paths
This commit is contained in:
Dean 2026-10-13 01:29:30 +13:00 committed by GitHub
commit 71c3dbb722
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -71,6 +71,8 @@ Args ParseArgs(int argc, char* argv[]) {
args.windowsGui = true;
} else if (arg.rfind("--", 0) == 0 || arg == "unused-filter") {
throw std::runtime_error("unknown option: " + arg);
} else if (arg.empty()) {
throw std::runtime_error("input and output paths must be nonempty");
} else if (args.inputPath.empty()) {
args.inputPath = arg;
} else if (args.outputPath.empty()) {

View File

@ -163,6 +163,13 @@ void unknownOption() {
expectThrows({"--", "input.elf", "output.elf"}, "unknown option: --");
}
void emptyPositionals() {
for (const auto& arguments : std::vector<std::vector<std::string>>{
{"", "input.elf", "output.elf"}, {"input.elf", "", "output.elf"},
{"", "output.elf"}, {"input.elf", ""}})
expectThrows(arguments, "input and output paths must be nonempty");
}
void tooManyPositionals() {
expectThrows({"input.elf", "output.elf", "extra.elf"}, "unexpected argument: extra.elf");
}
@ -211,6 +218,7 @@ int main() {
unusedFilterRejectsDuplicates();
unusedFilterBareWordIsUnknown();
unknownOption();
emptyPositionals();
tooManyPositionals();
windowsDiagnosticsRequiresWindows();
windowsGuiRequiresWindows();