mirror of https://github.com/microsoft/clang.git
[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! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265125 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
37c4b0f98c
commit
3eb041dcd1
|
@ -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.
|
||||
|
|
|
@ -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 '('}}
|
||||
<<<<
|
Loading…
Reference in New Issue