Skip to content

Commit

Permalink
[JsonWriter] Do not break in EscapeString when encountering a null by…
Browse files Browse the repository at this point in the history
…te (grpc#33127)

Instead just Utf-16 encode the null byte when dumping the value to a
string form.

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
  • Loading branch information
yijiem authored May 15, 2023
1 parent 87a0eb4 commit 3526def
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/core/lib/json/json_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ void JsonWriter::EscapeString(const std::string& string) {
OutputChar('"');
for (size_t idx = 0; idx < string.size(); ++idx) {
uint8_t c = static_cast<uint8_t>(string[idx]);
if (c == 0) {
break;
} else if (c >= 32 && c <= 126) {
if (c >= 32 && c <= 126) {
if (c == '\\' || c == '"') OutputChar('\\');
OutputChar(static_cast<char>(c));
} else if (c < 32 || c == 127) {
Expand Down
1 change: 1 addition & 0 deletions test/core/json/corpus/testcase-6037245441474560
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"\u0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
1 change: 1 addition & 0 deletions test/core/json/corpus/testcase-6329722588758016
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"\u0000"

0 comments on commit 3526def

Please sign in to comment.