From: Stephen Hemminger Date: Tue, 23 Jan 2024 04:26:08 +0000 (-0800) Subject: color: handle case where fmt is NULL X-Git-Tag: v6.8.0~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da5a2d94dc012a923133e94bed25a67f6bd74657;p=thirdparty%2Fiproute2.git 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. Reported-by: Pedro Tammela Signed-off-by: Stephen Hemminger --- diff --git a/lib/color.c b/lib/color.c index 599768472..cd0f9f750 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) {