Skip to content

Commit 92a9c4b

Browse files
committed
Fix overflow when searching for <#
ede6bf7 increments the buffer pointer to early when searching for the <# prefix to stop lexing an operator, so the source buffer is accessed 1 byte off the end. Thanks ASan and thanks @gparker42! rdar://problem/28457876
1 parent afd00af commit 92a9c4b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/Parse/Lexer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,11 @@ static bool isRightBound(const char *tokEnd, bool isLeftBound,
680680

681681
static bool rangeContainsPlaceholderEnd(const char *CurPtr,
682682
const char *End) {
683-
while (CurPtr++ < End - 1) {
684-
if (*CurPtr== '\n') {
683+
for (auto SubStr = CurPtr; SubStr != End - 1; ++SubStr) {
684+
if (SubStr[0] == '\n') {
685685
return false;
686686
}
687-
if (CurPtr[0] == '#' && CurPtr[1] == '>') {
687+
if (SubStr[0] == '#' && SubStr[1] == '>') {
688688
return true;
689689
}
690690
}
@@ -710,7 +710,7 @@ void Lexer::lexOperatorIdentifier() {
710710
// started with a '.'.
711711
if (*CurPtr == '.' && *TokStart != '.')
712712
break;
713-
if (Identifier::isEditorPlaceholder(StringRef(CurPtr, 2)) &&
713+
if (Identifier::isEditorPlaceholder(StringRef(CurPtr, BufferEnd-CurPtr)) &&
714714
rangeContainsPlaceholderEnd(CurPtr + 2, BufferEnd)) {
715715
break;
716716
}

0 commit comments

Comments
 (0)