[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240122164336.12119994@hermes.local>
Date: Mon, 22 Jan 2024 16:43:36 -0800
From: Stephen Hemminger <stephen@...workplumber.org>
To: Pedro Tammela <pctammela@...atatu.com>
Cc: netdev@...r.kernel.org
Subject: Re: [PATCH iproute2 1/2] color: use empty format string instead of
NULL in vfprintf
On Mon, 22 Jan 2024 18:05:45 -0300
Pedro Tammela <pctammela@...atatu.com> wrote:
> NULL is passed in the 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.
>
> The following is an example of one crash in musl based systems/containers:
> tc qdisc add dev dummy0 handle 1: root choke limit 1000 bandwidth 10000
> tc qdisc replace dev dummy0 handle 1: root choke limit 1000 bandwidth 10000 min 100
> tc qdisc show dev dummy0
>
> Signed-off-by: Pedro Tammela <pctammela@...atatu.com>
> ---
> lib/color.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Wouldn't it be simpler to just add a short circuit check.
This would fix the color case as well.
diff --git a/lib/color.c b/lib/color.c
index 59976847295c..cd0f9f7509b5 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -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) {
Powered by blists - more mailing lists