Skip to content

Commit

Permalink
Fix out-of-bounds read. (open-source-parsers#1503)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vslashg and baylesj authored Sep 10, 2024
1 parent 0a9b9d9 commit 3c2205c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3c2205c

Please sign in to comment.