aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2022-12-15 20:36:17 -0500
committerJohn Thacker <johnthacker@gmail.com>2022-12-16 12:20:30 +0000
commit5b96d57b18d2d184e503a517b8cbc63ad721ca8e (patch)
tree7efd4e98f84a42376ee30f91b9d8d0e96fc1b7f7 /wsutil
parentae148498649e38105607e9da2262fc276ffe2049 (diff)
protobuf: Do not crash on zero length bytes element
If a field name has been written to the json dumper for a bytes element (Base64), then a Base64 value must be written later, even if the value is zero length. Move the JSON_DUMPER_FLAGS_NO_DEBUG flag to the json_dumper header, and use it in the protobuf dissector, so that errors in the JSON dumper state transitions do not abort the application through a ws_error() call. Use DISSECTOR_ASSERT in that case, since it should happen only with a dissector bug (as with the zero bytes elements issue fixed here), not with malformed packets. Only instantiate the json_dumper and create its output string if we intend on displaying its output, instead of doing so whenever we have a message type name. Fix #18730.
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/json_dumper.c1
-rw-r--r--wsutil/json_dumper.h1
2 files changed, 1 insertions, 1 deletions
diff --git a/wsutil/json_dumper.c b/wsutil/json_dumper.c
index 0a61593389..731594a6d6 100644
--- a/wsutil/json_dumper.c
+++ b/wsutil/json_dumper.c
@@ -34,7 +34,6 @@ enum json_dumper_element_type {
#define JSON_DUMPER_HAS_NAME (1 << 3)
#define JSON_DUMPER_FLAGS_ERROR (1 << 16) /* Output flag: an error occurred. */
-#define JSON_DUMPER_FLAGS_NO_DEBUG (1 << 17) /* Input flag: disable debug prints (intended for speeding up fuzzing). */
enum json_dumper_change {
JSON_DUMPER_BEGIN,
diff --git a/wsutil/json_dumper.h b/wsutil/json_dumper.h
index 84a2c0df97..966c1afa76 100644
--- a/wsutil/json_dumper.h
+++ b/wsutil/json_dumper.h
@@ -55,6 +55,7 @@ typedef struct json_dumper {
GString *output_string; /**< Output GLib strings. If it is not NULL, JSON will be dumped in the string. */
#define JSON_DUMPER_FLAGS_PRETTY_PRINT (1 << 0) /* Enable pretty printing. */
#define JSON_DUMPER_DOT_TO_UNDERSCORE (1 << 1) /* Convert dots to underscores in keys */
+#define JSON_DUMPER_FLAGS_NO_DEBUG (1 << 17) /* Disable fatal ws_error messsges on error(intended for speeding up fuzzing). */
int flags;
/* for internal use, initialize with zeroes. */
int current_depth;