Skip to contentSkip to conversation

netlink: fix print_string when the value is NULL

PATCH Applied Michel Lind 4 participants 7 messages Jul 25, 2025 – Aug 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netlink: fix print_string when the value is NULL

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.

---
 json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
json_print.c +1 -1
index e07c651..75e6cd9 100644
@@ -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);
 	}
 }
 
Signature · 7 lines
2.50.1


-- 
 _o) Michel Lind
_( ) identities: https://keyoxide.org/5dce2e7e9c3b1cffd335c1d78b229d2f7ccc04f2
     README:     https://fedoraproject.org/wiki/User:Salimma#README
#1 lore raw
Quoted 14 lines · Michel Lind

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);
      |
```
Quoted 6 lines

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.

Applied, thank you.

It's a bit surprising that I didn't hit this problem as I always test building with "-Wall -Wextra -Werror". I suppose this option is not contained in -Wall or -Wextra.

Michal

Quoted 25 lines
---
 json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
json_print.c +1 -1
index e07c651..75e6cd9 100644
@@ -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);
 	}
 }
 
Signature · 7 lines
2.50.1


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

Hi Michal,

Quoted 47 lines · Michal Kubecek
Quoted 14 lines · Michel Lind

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);
      |
```
Quoted 6 lines

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.

Applied, thank you.

It's a bit surprising that I didn't hit this problem as I always test building with "-Wall -Wextra -Werror". I suppose this option is not contained in -Wall or -Wextra.

Michal

Quoted 17 lines
---
 json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
json_print.c +1 -1
index e07c651..75e6cd9 100644
@@ -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);
 	}
 }
 
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.50.1

As b70c92866102 ("netlink: fix missing headers in text output") was backported as well for the 6.14.2 version, should that get as well a new release 6.14.3 with the fix?

Regards,
Salvatore

#3 lore raw

Dne Sun, Aug 10, 2025 at 09:14:26AM GMT, Salvatore Bonaccorso napsal:

Quoted 50 lines

Hi Michal,

Quoted 47 lines · Michal Kubecek
Quoted 14 lines · Michel Lind

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);
      |
```
Quoted 6 lines

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.

Applied, thank you.

It's a bit surprising that I didn't hit this problem as I always test building with "-Wall -Wextra -Werror". I suppose this option is not contained in -Wall or -Wextra.

Michal

Quoted 17 lines
---
 json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
json_print.c +1 -1
index e07c651..75e6cd9 100644
@@ -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);
 	}
 }
 
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.50.1

As b70c92866102 ("netlink: fix missing headers in text output") was backported as well for the 6.14.2 version, should that get as well a new release 6.14.3 with the fix?

I could do that but it didn't seem necessary. If I understand correctly, this patch does not address any runtime issue (at least not until there is an actual call of print_string() with null value and fmt containing a template); and the build issue only happens with a very specific compiler option which is not only not default but is not included even in "-Wall -Wextra" (not even in gcc15).

I'm aware that the commit message says that Fedora uses that compiler option in its package builds but that's something that can be addressed by a distribution patch. Therefore my plan was to cherry pick the commit into ethtool-6.14.y branch but not to release 6.14.3 unless something more serious shows up.

But if I misunderstood the situation and 6.14.3 with this commit would be really helpful, I can reconsider.

Michal

#4 lore raw

Hi,

Quoted 65 lines · Michal Kubecek

Dne Sun, Aug 10, 2025 at 09:14:26AM GMT, Salvatore Bonaccorso napsal:

Quoted 50 lines

Hi Michal,

Quoted 47 lines · Michal Kubecek
Quoted 14 lines · Michel Lind

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);
      |
```
Quoted 6 lines

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.

Applied, thank you.

It's a bit surprising that I didn't hit this problem as I always test building with "-Wall -Wextra -Werror". I suppose this option is not contained in -Wall or -Wextra.

Michal

Quoted 17 lines
---
 json_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
json_print.c +1 -1
index e07c651..75e6cd9 100644
@@ -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);
 	}
 }
 
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.50.1

As b70c92866102 ("netlink: fix missing headers in text output") was backported as well for the 6.14.2 version, should that get as well a new release 6.14.3 with the fix?

I could do that but it didn't seem necessary. If I understand correctly, this patch does not address any runtime issue (at least not until there is an actual call of print_string() with null value and fmt containing a template); and the build issue only happens with a very specific compiler option which is not only not default but is not included even in "-Wall -Wextra" (not even in gcc15).

Quoted 8 lines

I'm aware that the commit message says that Fedora uses that compiler option in its package builds but that's something that can be addressed by a distribution patch. Therefore my plan was to cherry pick the commit into ethtool-6.14.y branch but not to release 6.14.3 unless something more serious shows up.

But if I misunderstood the situation and 6.14.3 with this commit would be really helpful, I can reconsider.

No not urgent, but I hit the same issue when preparing 6.14.2 for Debian trixie. But I can equally just cherry-pick the commit locally and then drop it once 6.14.3 is released.

So really no hurry about that.

Regards,
Salvatore

#5 lore raw

Dne Mon, Aug 11, 2025 at 10:23:38PM GMT, Salvatore Bonaccorso napsal:

Quoted 5 lines

No not urgent, but I hit the same issue when preparing 6.14.2 for Debian trixie. But I can equally just cherry-pick the commit locally and then drop it once 6.14.3 is released.

So really no hurry about that.

OK, I'll release 6.14.3 on Friday when I'm back home and can do it from my desktop which will be a bit easier.

Michal

#6 lore raw
In reply to Michel Lind
This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:

Hello:

This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:

Quoted 8 lines · On Thu, 24 Jul 2025 19:48:11 -0500 you wrote:

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.

[...]

Here is the summary with links:
- [ethtool] netlink: fix print_string when the value is NULL

    https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit/?id=41d6105250c8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html