All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michel Lind <michel@michel-slm.name>
To: Michal Kubecek <mkubecek@suse.cz>
Cc: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH ethtool] netlink: fix print_string when the value is NULL
Date: Thu, 24 Jul 2025 19:48:11 -0500	[thread overview]
Message-ID: <aILUS-BlVm5tubAF@maurice.local> (raw)

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]

The previous fix in commit b70c92866102 ("netlink: fix missing headers
in text output") handles the case when value is NULL by still using
`fprintf` but passing no value.

This fails if `-Werror=format-security` is passed to gcc, as is the
default in distros like Fedora.

```
json_print.c: In function 'print_string':
json_print.c:147:25: error: format not a string literal and no format arguments [-Werror=format-security]
  147 |                         fprintf(stdout, fmt);
      |
```

Use `fprintf(stdout, "%s", fmt)` instead, using the format string as the
value, since in this case we know it is just a string without format
chracters.

Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Michel Lind <michel@michel-slm.name>
---
 json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/json_print.c b/json_print.c
index e07c651..75e6cd9 100644
--- a/json_print.c
+++ b/json_print.c
@@ -144,7 +144,7 @@ void print_string(enum output_type type,
 		if (value)
 			fprintf(stdout, fmt, value);
 		else
-			fprintf(stdout, fmt);
+			fprintf(stdout, "%s", fmt);
 	}
 }
 
-- 
2.50.1


-- 
 _o) Michel Lind
_( ) identities: https://keyoxide.org/5dce2e7e9c3b1cffd335c1d78b229d2f7ccc04f2
     README:     https://fedoraproject.org/wiki/User:Salimma#README

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

             reply	other threads:[~2025-07-25  0:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-25  0:48 Michel Lind [this message]
2025-08-07 23:05 ` [PATCH ethtool] netlink: fix print_string when the value is NULL Michal Kubecek
2025-08-10  7:14   ` Salvatore Bonaccorso
2025-08-11 20:07     ` Michal Kubecek
2025-08-11 20:23       ` Salvatore Bonaccorso
2025-08-12  6:14         ` Michal Kubecek
2025-08-07 23:49 ` patchwork-bot+netdevbpf

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=aILUS-BlVm5tubAF@maurice.local \
    --to=michel@michel-slm.name \
    --cc=kuba@kernel.org \
    --cc=mkubecek@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.