]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: return error if table does not exist
authorFlorian Westphal <fw@strlen.de>
Thu, 27 Mar 2025 08:07:52 +0000 (09:07 +0100)
committerFlorian Westphal <fw@strlen.de>
Thu, 27 Mar 2025 08:13:43 +0000 (09:13 +0100)
Identical bug and thus same fix as
853d3a2d3cbd ("rule: return error if table does not exist"),
but this time for json.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/json.c
tests/shell/testcases/bogons/nft-j-f/list_a_destroyed_table_crash [new file with mode: 0644]

index 96413d70895ae6ddbab99888f4f44606a500de7a..831bc90f08332fb101d9bc7535b09ae5f4a3b332 100644 (file)
@@ -1973,10 +1973,15 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
        struct table *table = NULL;
        json_t *root;
 
-       if (cmd->handle.table.name)
+       if (cmd->handle.table.name) {
                table = table_cache_find(&ctx->nft->cache.table_cache,
                                         cmd->handle.table.name,
                                         cmd->handle.family);
+               if (!table) {
+                       errno = ENOENT;
+                       return -1;
+               }
+       }
 
        switch (cmd->obj) {
        case CMD_OBJ_TABLE:
diff --git a/tests/shell/testcases/bogons/nft-j-f/list_a_destroyed_table_crash b/tests/shell/testcases/bogons/nft-j-f/list_a_destroyed_table_crash
new file mode 100644 (file)
index 0000000..f06145c
--- /dev/null
@@ -0,0 +1,3 @@
+table t
+list table t
+destroy table t