]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_json: fix crash in json_parse_set_stmt_list
authorSebastian Walz (sivizius) <sebastian.walz@secunet.com>
Mon, 19 Aug 2024 22:09:26 +0000 (00:09 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 21 Aug 2024 21:22:47 +0000 (23:22 +0200)
Due to missing `NULL`-check, there will be a segfault for invalid statements.

Fixes: 07958ec53830 ("json: add set statement list support")
Signed-off-by: Sebastian Walz (sivizius) <sebastian.walz@secunet.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_json.c

index d18188d81b3f21c1b858feb1509ddc07e8e10e09..bbe3b1c59192c6e526d34c1c82a0d100df38b3a4 100644 (file)
@@ -2380,7 +2380,7 @@ static void json_parse_set_stmt_list(struct json_ctx *ctx,
                                     json_t *stmt_json)
 {
        struct list_head *head;
-       struct stmt *tmp;
+       struct stmt *stmt;
        json_t *value;
        size_t index;
 
@@ -2392,9 +2392,14 @@ static void json_parse_set_stmt_list(struct json_ctx *ctx,
 
        head = stmt_list;
        json_array_foreach(stmt_json, index, value) {
-               tmp = json_parse_stmt(ctx, value);
-               list_add(&tmp->list, head);
-               head = &tmp->list;
+               stmt = json_parse_stmt(ctx, value);
+               if (!stmt) {
+                       json_error(ctx, "Parsing set statements array at index %zd failed.", index);
+                       stmt_list_free(stmt_list);
+                       return;
+               }
+               list_add(&stmt->list, head);
+               head = &stmt->list;
        }
 }