mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[lldb-moduleimport-test] Validate input to prevent crashes.
This commit is contained in:
@@ -199,6 +199,28 @@ int main(int argc, char **argv) {
|
||||
DumpTypeFromMangled.removeArgument();
|
||||
InputNames.removeArgument();
|
||||
|
||||
auto validateInputFile = [](std::string Filename) {
|
||||
if (Filename.empty())
|
||||
return true;
|
||||
if (!llvm::sys::fs::exists(llvm::Twine(Filename))) {
|
||||
llvm::errs() << Filename << " does not exists, exiting.\n";
|
||||
return false;
|
||||
}
|
||||
if (!llvm::sys::fs::is_regular_file(llvm::Twine(Filename))) {
|
||||
llvm::errs() << Filename << " is not a regular file, exiting.\n";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
for (auto &InputFilename : InputNames)
|
||||
if (!validateInputFile(InputFilename))
|
||||
return 1;
|
||||
if (!validateInputFile(DumpTypeFromMangled))
|
||||
return 1;
|
||||
if (!validateInputFile(DumpDeclFromMangled))
|
||||
return 1;
|
||||
|
||||
// Fetch the serialized module bitstreams from the Mach-O files and
|
||||
// register them with the module loader.
|
||||
llvm::SmallVector<std::pair<char *, uint64_t>, 8> Modules;
|
||||
|
||||
Reference in New Issue
Block a user