diff options
author | Reid Kleckner <rnk@google.com> | 2020-12-09 13:30:22 -0800 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2020-12-09 13:32:28 -0800 |
commit | c8466a57310a0f10563e4a5a511e8c6386599cfe (patch) | |
tree | 9b189ea2281520a3a98f0e034138fbb2bac5174c | |
parent | 7ea94922fa0d8ac6b041c0dc4cd9f8135f0e60bb (diff) | |
download | llvm-c8466a57310a0f10563e4a5a511e8c6386599cfe.zip llvm-c8466a57310a0f10563e4a5a511e8c6386599cfe.tar.gz llvm-c8466a57310a0f10563e4a5a511e8c6386599cfe.tar.bz2 |
Avoid a possible one-byte OOB read off of .drectve sections
Pointed out by Ryan Prichard
-rw-r--r-- | lld/COFF/DriverUtils.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index f289e66..1996442 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -883,8 +883,10 @@ ParsedDirectives ArgParser::parseDirectives(StringRef s) { tok.startswith_lower("-include:")) result.includes.push_back(tok.substr(strlen("/include:"))); else { - // Save non-null-terminated strings to make proper C strings. - bool HasNul = tok.data()[tok.size()] == '\0'; + // Copy substrings that are not valid C strings. The tokenizer may have + // already copied quoted arguments for us, so those do not need to be + // copied again. + bool HasNul = tok.end() != s.end() && tok.data()[tok.size()] == '\0'; rest.push_back(HasNul ? tok.data() : saver.save(tok).data()); } } |