netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft] src: parser_json: fix format string bugs
Date: Thu, 23 Oct 2025 14:21:33 +0200	[thread overview]
Message-ID: <20251023122235.13019-1-fw@strlen.de> (raw)

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 | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/parser_json.c b/src/parser_json.c
index e78262505d24..7b4f33848ce1 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -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;
 	}
-- 
2.51.0


                 reply	other threads:[~2025-10-23 12:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251023122235.13019-1-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).