Skip to contentSkip to conversation

color: handle case where fmt is NULL

PATCH Applied Stephen Hemminger 2 participants 2 messages Jan 23, 2024 – Jan 24, 2024

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

PATCH 1/1 color: handle case where fmt is NULL

There are cases where NULL is passed as format string when nothing is to be printed. This is commonly done in the print_bool function when a flag is false. Glibc seems to handle this case nicely but for musl it will cause a segmentation fault

Since nothing needs to be printed, in this case; just check for NULL and return.

---
 lib/color.c | 3 +++
 1 file changed, 3 insertions(+)
lib/color.c +3 -0
index 59976847295c..cd0f9f7509b5 100644
@@ -140,6 +140,9 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 	int ret = 0;
 	va_list args;
 
+	if (fmt == NULL)
+		return 0;
+
 	va_start(args, fmt);
 
 	if (!color_is_enabled || attr == COLOR_NONE) {
Signature · 1 line
2.43.0
#1 lore raw
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 9 lines · On Mon, 22 Jan 2024 20:30:10 -0800 you wrote:

There are cases where NULL is passed as format string when nothing is to be printed. This is commonly done in the print_bool function when a flag is false. Glibc seems to handle this case nicely but for musl it will cause a segmentation fault

Since nothing needs to be printed, in this case; just check for NULL and return.

[...]

Here is the summary with links:
- [iproute2] color: handle case where fmt is NULL

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=da5a2d94dc01

You are awesome, thank you!

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