mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[lldb-moduleimport-test] Validate input to prevent crashes.
This commit is contained in:
@@ -7,6 +7,22 @@
|
|||||||
// RUN: sed -ne '/--->/s/^.*---> *//p' < %S/Inputs/decl-reconstr-names.txt > %t.check
|
// RUN: sed -ne '/--->/s/^.*---> *//p' < %S/Inputs/decl-reconstr-names.txt > %t.check
|
||||||
|
|
||||||
// RUN: %target-build-swift -emit-executable %s -g -o %t/DeclReconstr -emit-module
|
// RUN: %target-build-swift -emit-executable %s -g -o %t/DeclReconstr -emit-module
|
||||||
|
|
||||||
|
// Input validation tests.
|
||||||
|
// RUN: not %lldb-moduleimport-test patatino 2>&1 | %FileCheck %s \
|
||||||
|
// RUN: --check-prefix=INVALID-INPUT
|
||||||
|
// INVALID-INPUT: patatino does not exists, exiting.
|
||||||
|
|
||||||
|
// RUN: not %lldb-moduleimport-test %t/DeclReconstr \
|
||||||
|
// RUN: --decl-from-mangled=patatino 2>&1 | \
|
||||||
|
// RUN: %FileCheck %s --check-prefix=INVALID-DECL
|
||||||
|
// INVALID-DECL: patatino does not exists, exiting.
|
||||||
|
|
||||||
|
// RUN: not %lldb-moduleimport-test %t/DeclReconstr \
|
||||||
|
// RUN: --type-from-mangled=patatino 2>&1 | \
|
||||||
|
// RUN: %FileCheck %s --check-prefix=INVALID-TYPE
|
||||||
|
// INVALID-TYPE: patatino does not exists, exiting.
|
||||||
|
|
||||||
// RUN: %lldb-moduleimport-test %t/DeclReconstr \
|
// RUN: %lldb-moduleimport-test %t/DeclReconstr \
|
||||||
// RUN: -decl-from-mangled=%t.input > %t.output 2>&1
|
// RUN: -decl-from-mangled=%t.input > %t.output 2>&1
|
||||||
// RUN: diff %t.check %t.output
|
// RUN: diff %t.check %t.output
|
||||||
|
|||||||
@@ -199,6 +199,28 @@ int main(int argc, char **argv) {
|
|||||||
DumpTypeFromMangled.removeArgument();
|
DumpTypeFromMangled.removeArgument();
|
||||||
InputNames.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
|
// Fetch the serialized module bitstreams from the Mach-O files and
|
||||||
// register them with the module loader.
|
// register them with the module loader.
|
||||||
llvm::SmallVector<std::pair<char *, uint64_t>, 8> Modules;
|
llvm::SmallVector<std::pair<char *, uint64_t>, 8> Modules;
|
||||||
|
|||||||
Reference in New Issue
Block a user