[Lexer] Don't read out of bounds if a conflict marker is at the end of a file

This can happen as we look for '<<<<' while scanning tokens but then expect
'<<<<\n' to tell apart perforce from diff3 conflict markers. Just harden
the pointer arithmetic.

Found by libfuzzer + asan!

llvm-svn: 265125
This commit is contained in:
Benjamin Kramer 2016-04-01 09:58:45 +00:00
parent a5d09f64a1
commit e550bbdf9d
2 changed files with 12 additions and 1 deletions

View File

@ -2610,7 +2610,7 @@ static const char *FindConflictEnd(const char *CurPtr, const char *BufferEnd,
ConflictMarkerKind CMK) {
const char *Terminator = CMK == CMK_Perforce ? "<<<<\n" : ">>>>>>>";
size_t TermLen = CMK == CMK_Perforce ? 5 : 7;
StringRef RestOfBuffer(CurPtr+TermLen, BufferEnd-CurPtr-TermLen);
auto RestOfBuffer = StringRef(CurPtr, BufferEnd - CurPtr).substr(TermLen);
size_t Pos = RestOfBuffer.find(Terminator);
while (Pos != StringRef::npos) {
// Must occur at start of line.

View File

@ -0,0 +1,11 @@
// RUN: %clang_cc1 %s -verify -fsyntax-only
// vim: set binary noeol:
// This file intentionally ends without a \n on the last line. Make sure your
// editor doesn't add one.
>>>> ORIGINAL
// expected-error@-1 {{version control conflict marker in file}}
<<<<
// expected-error@-1 {{expected identifier or '('}}
<<<<