Fix out-of-bounds read.

getLocationLIneAndColumn would read past the end of the provided buffer if generating an error message at the end of the stream, if the final character was `\r`.
This commit is contained in:
vslashg 2023-07-19 18:05:33 -04:00 committed by GitHub
parent 69098a18b9
commit 7168e3fd52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -773,7 +773,7 @@ void Reader::getLocationLineAndColumn(Location location, int& line,
while (current < location && current != end_) { while (current < location && current != end_) {
Char c = *current++; Char c = *current++;
if (c == '\r') { if (c == '\r') {
if (*current == '\n') if (current != end_ && *current == '\n')
++current; ++current;
lastLineStart = current; lastLineStart = current;
++line; ++line;
@ -1825,7 +1825,7 @@ void OurReader::getLocationLineAndColumn(Location location, int& line,
while (current < location && current != end_) { while (current < location && current != end_) {
Char c = *current++; Char c = *current++;
if (c == '\r') { if (c == '\r') {
if (*current == '\n') if (current != end_ && *current == '\n')
++current; ++current;
lastLineStart = current; lastLineStart = current;
++line; ++line;