]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_json: Proper ct expectation attribute parsing
authorPhil Sutter <phil@nwl.cc>
Wed, 20 Sep 2023 17:11:45 +0000 (19:11 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 3 Nov 2023 11:23:37 +0000 (12:23 +0100)
commit 34c1337296807b3a3147c95268f5e4ca70811779 upstream.

Parts of the code were unsafe (parsing 'I' format into uint32_t), the
rest just plain wrong (parsing 'o' format into char *tmp). Introduce a
temporary int variable to parse into.

Fixes: 1dd08fcfa07a4 ("src: add ct expectations support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/parser_json.c

index f61cc14eebf7b987899244fc221807e587af1eff..996004acc2d6b3ac499e314edb7b3dea88041d15 100644 (file)
@@ -3331,8 +3331,8 @@ static struct cmd *json_parse_cmd_add_object(struct json_ctx *ctx,
 {
        const char *family, *tmp, *rate_unit = "packets", *burst_unit = "bytes";
        uint32_t l3proto = NFPROTO_UNSPEC;
+       int inv = 0, flags = 0, i;
        struct handle h = { 0 };
-       int inv = 0, flags = 0;
        struct obj *obj;
        json_t *jflags;
 
@@ -3483,11 +3483,12 @@ static struct cmd *json_parse_cmd_add_object(struct json_ctx *ctx,
                                return NULL;
                        }
                }
-               if (!json_unpack(root, "{s:o}", "dport", &tmp))
-                       obj->ct_expect.dport = atoi(tmp);
-               json_unpack(root, "{s:I}", "timeout", &obj->ct_expect.timeout);
-               if (!json_unpack(root, "{s:o}", "size", &tmp))
-                       obj->ct_expect.size = atoi(tmp);
+               if (!json_unpack(root, "{s:i}", "dport", &i))
+                       obj->ct_expect.dport = i;
+               if (!json_unpack(root, "{s:i}", "timeout", &i))
+                       obj->ct_expect.timeout = i;
+               if (!json_unpack(root, "{s:i}", "size", &i))
+                       obj->ct_expect.size = i;
                break;
        case CMD_OBJ_LIMIT:
                obj->type = NFT_OBJECT_LIMIT;