Commit c8466a57 authored by Reid Kleckner's avatar Reid Kleckner
Browse files

Avoid a possible one-byte OOB read off of .drectve sections

Pointed out by Ryan Prichard
parent 7ea94922
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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());
    }
  }