Skip to content

Commit 3c2205c

Browse files
vslashgbaylesj
andauthored
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>
1 parent 0a9b9d9 commit 3c2205c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib_json/json_reader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ void Reader::getLocationLineAndColumn(Location location, int& line,
761761
while (current < location && current != end_) {
762762
Char c = *current++;
763763
if (c == '\r') {
764-
if (*current == '\n')
764+
if (current != end_ && *current == '\n')
765765
++current;
766766
lastLineStart = current;
767767
++line;
@@ -1801,7 +1801,7 @@ void OurReader::getLocationLineAndColumn(Location location, int& line,
18011801
while (current < location && current != end_) {
18021802
Char c = *current++;
18031803
if (c == '\r') {
1804-
if (*current == '\n')
1804+
if (current != end_ && *current == '\n')
18051805
++current;
18061806
lastLineStart = current;
18071807
++line;

0 commit comments

Comments
 (0)