From 81de3f433ede80d50c8373892f2aaf2b7a67b94e Mon Sep 17 00:00:00 2001 From: Costa Tsaousis Date: Thu, 20 Feb 2025 16:28:34 +0200 Subject: [PATCH] allow parsing empty json arrays and objects (#19685) --- src/collectors/log2journal/log2journal-json.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/collectors/log2journal/log2journal-json.c b/src/collectors/log2journal/log2journal-json.c index be369ffe99380c..9a3068911e0568 100644 --- a/src/collectors/log2journal/log2journal-json.c +++ b/src/collectors/log2journal/log2journal-json.c @@ -513,6 +513,12 @@ static inline bool json_parse_array(LOG_JSON_STATE *js) { size_t index = 0; do { + const char *s = json_current_pos(js); + if(*s == ']') { + json_consume_char(js); + break; + } + if(!json_key_index_and_push(js, index)) return false; @@ -524,7 +530,7 @@ static inline bool json_parse_array(LOG_JSON_STATE *js) { if(!json_expect_char_after_white_space(js, ",]")) return false; - const char *s = json_current_pos(js); + s = json_current_pos(js); json_consume_char(js); if(*s == ',') { index++; @@ -545,6 +551,12 @@ static inline bool json_parse_object(LOG_JSON_STATE *js) { json_consume_char(js); do { + const char *s = json_current_pos(js); + if(*s == '}') { + json_consume_char(js); + break; + } + if (!json_expect_char_after_white_space(js, "\"")) return false; @@ -564,7 +576,7 @@ static inline bool json_parse_object(LOG_JSON_STATE *js) { if(!json_expect_char_after_white_space(js, ",}")) return false; - const char *s = json_current_pos(js); + s = json_current_pos(js); json_consume_char(js); if(*s == ',') continue;