File: netlink-fix-print_string-when-the-value-is-NULL.patch

package info (click to toggle)
ethtool 1%3A6.15-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,996 kB
  • sloc: ansic: 66,004; sh: 97; makefile: 88; xml: 17
file content (45 lines) | stat: -rw-r--r-- 1,389 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From: Michel Lind <michel@michel-slm.name>
Date: Thu, 24 Jul 2025 19:48:11 -0500
Subject: netlink: fix print_string when the value is NULL
Origin: https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit?id=41d6105250c8293eddeb5f9332434728e7da4335

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 e07c651f477b..75e6cd97048c 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