Skip to content

Commit 94aee4f

Browse files
authored
Reject unescaped control characters in JSON strings (#1663)
RFC 8259 requires that control characters (U+0000-U+001F) be escaped when they appear inside strings. jsoncpp previously accepted them silently. Add a check in Reader::decodeString and OurReader::decodeString to return an error when an unescaped control character is encountered. Fixes #1546
1 parent 8661f9e commit 94aee4f

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/lib_json/json_reader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ bool Reader::decodeString(Token& token, String& decoded) {
655655
return addError("Bad escape sequence in string", token, current);
656656
}
657657
} else {
658+
if (static_cast<unsigned char>(c) < 0x20)
659+
return addError("Control character in string", token, current - 1);
658660
decoded += c;
659661
}
660662
}
@@ -1690,6 +1692,8 @@ bool OurReader::decodeString(Token& token, String& decoded) {
16901692
return addError("Bad escape sequence in string", token, current);
16911693
}
16921694
} else {
1695+
if (static_cast<unsigned char>(c) < 0x20)
1696+
return addError("Control character in string", token, current - 1);
16931697
decoded += c;
16941698
}
16951699
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
""

0 commit comments

Comments
 (0)