diff options
author | Shoaib Meenai <smeenai@fb.com> | 2019-04-15 21:31:28 +0000 |
---|---|---|
committer | Shoaib Meenai <smeenai@fb.com> | 2019-04-15 21:31:28 +0000 |
commit | c8df4fb9c3865eac52a99602c26bbc070098c3d4 (patch) | |
tree | bcd85d457a958e3866247a52683b90563a79e508 /llvm/lib/Support/CommandLine.cpp | |
parent | c8497467edc5766ae81ffbde58159f8c6af50803 (diff) | |
download | bcm5719-llvm-c8df4fb9c3865eac52a99602c26bbc070098c3d4.tar.gz bcm5719-llvm-c8df4fb9c3865eac52a99602c26bbc070098c3d4.zip |
[Support] Fix recursive response file expansion guard
Response file expansion limits the amount of expansion to prevent
potential infinite recursion. However, the current logic assumes that
any argument beginning with @ is a response file, which is not true for
e.g. `-Xlinker -rpath -Xlinker @executable_path/../lib` on Darwin.
Having too many of these non-response file arguments beginning with @
prevents actual response files from being expanded. Instead, limit based
on the number of successful response file expansions, which should still
prevent infinite recursion but also avoid false positives.
Differential Revision: https://reviews.llvm.org/D60631
llvm-svn: 358452
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 98d06f65c79..0050002ff05 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -1040,7 +1040,7 @@ static bool ExpandResponseFile(StringRef FName, StringSaver &Saver, bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl<const char *> &Argv, bool MarkEOLs, bool RelativeNames) { - unsigned RspFiles = 0; + unsigned ExpandedRspFiles = 0; bool AllExpanded = true; // Don't cache Argv.size() because it can change. @@ -1058,14 +1058,16 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, // If we have too many response files, leave some unexpanded. This avoids // crashing on self-referential response files. - if (RspFiles++ > 20) + if (ExpandedRspFiles > 20) return false; // Replace this response file argument with the tokenization of its // contents. Nested response files are expanded in subsequent iterations. SmallVector<const char *, 0> ExpandedArgv; - if (!ExpandResponseFile(Arg + 1, Saver, Tokenizer, ExpandedArgv, - MarkEOLs, RelativeNames)) { + if (ExpandResponseFile(Arg + 1, Saver, Tokenizer, ExpandedArgv, MarkEOLs, + RelativeNames)) { + ++ExpandedRspFiles; + } else { // We couldn't read this file, so we leave it in the argument stream and // move on. AllExpanded = false; |