parser: decoder: json: restrict to one message
@@ -38,6 +38,7 @@ static int decode_json(struct flb_parser_dec *dec,
{
int ret;
int root_type;
+ int records;
char *buf;
const char *p;
size_t size;
@@ -53,11 +54,17 @@ static int decode_json(struct flb_parser_dec *dec,
return -1;
}
- ret = flb_pack_json(p, len, &buf, &size, &root_type);
+ ret = flb_pack_json_recs(p, len, &buf, &size, &root_type, &records);
if (ret != 0) {
return -1;
}
+ /* We expect to decode only one JSON element */
+ if (records != 1) {
+ flb_free(buf);
+ return -1;
+ }
+
/* Only process a packed JSON object */
if (root_type != FLB_PACK_JSON_OBJECT) {
flb_free(buf);
