]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: parser_json: fix format string bugs
authorFlorian Westphal <fw@strlen.de>
Thu, 23 Oct 2025 12:17:00 +0000 (14:17 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 23 Oct 2025 12:54:05 +0000 (14:54 +0200)
After adding fmt attribute annotation:
warning: format not a string literal and no format arguments [-Wformat-security]
  131 |         erec_queue(error(&loc, err->text), ctx->msgs);
In function 'json_events_cb':
warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type '__u32' {aka 'unsigned int'} [-Wformat=]

Fix that up too.

Fixes: 586ad210368b ("libnftables: Implement JSON parser")
Signed-off-by: Florian Westphal <fw@strlen.de>
src/parser_json.c

index e78262505d24372b8978f2b31e8bcbf60deab2f2..7b4f33848ce123983fed9216b9459322f8f90442 100644 (file)
@@ -128,7 +128,7 @@ static void json_lib_error(struct json_ctx *ctx, json_error_t *err)
                .last_column = err->column,
        };
 
-       erec_queue(error(&loc, err->text), ctx->msgs);
+       erec_queue(error(&loc, "%s", err->text), ctx->msgs);
 }
 
 __attribute__((format(printf, 2, 3)))
@@ -4558,6 +4558,7 @@ int nft_parse_json_filename(struct nft_ctx *nft, const char *filename,
        return ret;
 }
 
+__attribute__((format(printf, 2, 3)))
 static int json_echo_error(struct netlink_mon_handler *monh,
                           const char *fmt, ...)
 {
@@ -4630,7 +4631,7 @@ int json_events_cb(const struct nlmsghdr *nlh, struct netlink_mon_handler *monh)
 
        json = seqnum_to_json(nlh->nlmsg_seq);
        if (!json) {
-               json_echo_error(monh, "No JSON command found with seqnum %lu\n",
+               json_echo_error(monh, "No JSON command found with seqnum %u\n",
                                nlh->nlmsg_seq);
                return MNL_CB_OK;
        }