From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute 3/3] vdpa: don't build printf format out of vendor stats name
Date: Mon, 19 Oct 2026 13:03:04 -0700 [thread overview]
Message-ID: <20261019200623.816470-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20261019200623.816470-1-stephen@networkplumber.org>
pr_out_dev_net_vstats() appended " %lu " to the driver-supplied vendor
attribute name and used it as the printf format, so a '%' in the name was
taken as a conversion, and names over MAX_KEY_LEN aborted the rest of the
dump. Pass the name as a string argument with a literal format, which
drops the length limit, and use PRIu64 since uint64_t is not unsigned
long on 32-bit.
Fixes: 6f97e9c9337b ("vdpa: Add support for reading vdpa device statistics")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
vdpa/vdpa.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/vdpa/vdpa.c b/vdpa/vdpa.c
index e2b0a5b1..8719a636 100644
--- a/vdpa/vdpa.c
+++ b/vdpa/vdpa.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0+
#include <stdio.h>
+#include <inttypes.h>
#include <getopt.h>
#include <errno.h>
#include <sys/time.h>
@@ -890,10 +891,6 @@ static int cmd_dev_config(struct vdpa *vdpa, int argc, char **argv)
return -ENOENT;
}
-#define MAX_KEY_LEN 200
-/* 5 bytes for format */
-#define MAX_FMT_LEN (MAX_KEY_LEN + 5 + 1)
-
static void print_queue_type(struct nlattr *attr, uint16_t max_vqp, uint64_t features)
{
bool is_ctrl = false;
@@ -918,7 +915,6 @@ static void pr_out_dev_net_vstats(const struct nlmsghdr *nlh)
{
const char *name = NULL;
uint64_t features = 0;
- char fmt[MAX_FMT_LEN];
uint16_t max_vqp = 0;
struct nlattr *attr;
uint64_t v64;
@@ -936,15 +932,11 @@ static void pr_out_dev_net_vstats(const struct nlmsghdr *nlh)
break;
case VDPA_ATTR_DEV_VENDOR_ATTR_NAME:
name = mnl_attr_get_str(attr);
- if (strlen(name) > MAX_KEY_LEN)
- return;
-
- strcpy(fmt, name);
- strcat(fmt, " %lu ");
break;
case VDPA_ATTR_DEV_VENDOR_ATTR_VALUE:
v64 = mnl_attr_get_u64(attr);
- print_u64(PRINT_ANY, name, fmt, v64);
+ print_string(PRINT_FP, NULL, "%s ", name);
+ print_u64(PRINT_ANY, name, "%" PRIu64 " ", v64);
break;
}
}
--
2.53.0
prev parent reply other threads:[~2026-10-19 20:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 20:03 [PATCH iproute2 0/3] don't build printf formats out of names Stephen Hemminger
2026-10-19 20:03 ` [PATCH iproute 1/3] lib: " Stephen Hemminger
2026-10-19 20:03 ` [PATCH iproute 2/3] rdma: don't build printf formats out of keys Stephen Hemminger
2026-10-19 20:03 ` Stephen Hemminger [this message]
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=20261019200623.816470-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=netdev@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