Fix out-of-bounds read. (#1503)

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`.

Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
This commit is contained in:
vslashg 2024-09-09 20:32:17 -04:00 committed by GitHub
parent 0a9b9d9c6e
commit 3c2205cd97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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