From 69f656824e777feea4178d7f9b0591992cbb7b69 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Tue, 27 Jun 2023 08:03:33 +0800 Subject: [PATCH] Always append one double quote char in the end of string The returned value write_string_or_name() is not really checked, so one double quote char error is not identified and the broken json string is directly sent to the client. To address the issue, the workaround is always appending one double quote char in the end of string. TODO: 1. Find the root cause 2. Check the returned value of write_string_or_name() Longhorn 6190 Signed-off-by: Derek Su --- lib/json/json_write.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/json/json_write.c b/lib/json/json_write.c index a4b1bdfc5..e004d3fa9 100644 --- a/lib/json/json_write.c +++ b/lib/json/json_write.c @@ -393,6 +393,9 @@ write_string_or_name(struct spdk_json_write_ctx *w, const char *val, size_t len) { const uint8_t *p = val; const uint8_t *end = val + len; + bool failed = false; + int retval; + if (emit(w, "\"", 1)) { return fail(w); } @@ -415,14 +418,25 @@ write_string_or_name(struct spdk_json_write_ctx *w, const char *val, size_t len) codepoint = utf8_decode_unsafe_4(p); break; default: - return fail(w); + failed = true; + break; + } + + if (failed) { + break; } if (write_codepoint(w, codepoint)) { return fail(w); } p += codepoint_len; } - return emit(w, "\"", 1); + // Always append "\"" in the end of string + retval = emit(w, "\"", 1); + + if (failed) { + return fail(w); + } + return retval; } static int