Skip to content

Commit

Permalink
Added check for avoiding JSON flow parsing crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Nov 11, 2024
1 parent f412a7d commit 2e54589
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ZMQParserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2323,8 +2323,9 @@ u_int8_t ZMQParserInterface::parseJSONFlow(const char *payload,

if (f != NULL) {
int n = 0, rc;

if (json_object_get_type(f) == json_type_array) {
enum json_type t = json_object_get_type(f);

if (t == json_type_array) {
/* Flow array */
int id, num_elements = json_object_array_length(f);

Expand All @@ -2334,7 +2335,16 @@ u_int8_t ZMQParserInterface::parseJSONFlow(const char *payload,
if (rc > 0) n++;
}
} else {
rc = parseSingleJSONFlow(f, source_id);
if(t == json_type_string) {
json_object *obj = json_tokener_parse(json_object_get_string(f));

if(obj != NULL) {
rc = parseSingleJSONFlow(obj, source_id);
json_object_put(obj);
} else
rc = -1;
} else
rc = parseSingleJSONFlow(f, source_id);

if (rc > 0) n++;
}
Expand Down

0 comments on commit 2e54589

Please sign in to comment.