Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2 0/2] some musl fixes
@ 2024-01-22 21:05 Pedro Tammela
  2024-01-22 21:05 ` [PATCH iproute2 1/2] color: use empty format string instead of NULL in vfprintf Pedro Tammela
  2024-01-22 21:05 ` [PATCH iproute2 2/2] bpf: include libgen.h for basename Pedro Tammela
  0 siblings, 2 replies; 5+ messages in thread
From: Pedro Tammela @ 2024-01-22 21:05 UTC (permalink / raw)
  To: netdev; +Cc: Pedro Tammela

Fix subtle differences between musl and glibc which are
causing iproute2 to crash in Alpine Linux.

Pedro Tammela (2):
  color: use empty format string instead of NULL in vfprintf
  bpf: include libgen.h for basename

 lib/bpf_legacy.c | 1 +
 lib/color.c      | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH iproute2 1/2] color: use empty format string instead of NULL in vfprintf
  2024-01-22 21:05 [PATCH iproute2 0/2] some musl fixes Pedro Tammela
@ 2024-01-22 21:05 ` Pedro Tammela
  2024-01-23  0:43   ` Stephen Hemminger
  2024-01-22 21:05 ` [PATCH iproute2 2/2] bpf: include libgen.h for basename Pedro Tammela
  1 sibling, 1 reply; 5+ messages in thread
From: Pedro Tammela @ 2024-01-22 21:05 UTC (permalink / raw)
  To: netdev; +Cc: Pedro Tammela

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@mojatatu.com>
---
 lib/color.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/color.c b/lib/color.c
index 59976847..027e1703 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -143,7 +143,7 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 	va_start(args, fmt);
 
 	if (!color_is_enabled || attr == COLOR_NONE) {
-		ret = vfprintf(fp, fmt, args);
+		ret = vfprintf(fp, fmt ?: "", args);
 		goto end;
 	}
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH iproute2 2/2] bpf: include libgen.h for basename
  2024-01-22 21:05 [PATCH iproute2 0/2] some musl fixes Pedro Tammela
  2024-01-22 21:05 ` [PATCH iproute2 1/2] color: use empty format string instead of NULL in vfprintf Pedro Tammela
@ 2024-01-22 21:05 ` Pedro Tammela
  1 sibling, 0 replies; 5+ messages in thread
From: Pedro Tammela @ 2024-01-22 21:05 UTC (permalink / raw)
  To: netdev; +Cc: Pedro Tammela

In musl basename() is only available via libgen.h

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
---
 lib/bpf_legacy.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 844974e9..741eec8d 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c
@@ -18,6 +18,7 @@
 #include <stdarg.h>
 #include <limits.h>
 #include <assert.h>
+#include <libgen.h>
 
 #ifdef HAVE_ELF
 #include <libelf.h>
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2 1/2] color: use empty format string instead of NULL in vfprintf
  2024-01-22 21:05 ` [PATCH iproute2 1/2] color: use empty format string instead of NULL in vfprintf Pedro Tammela
@ 2024-01-23  0:43   ` Stephen Hemminger
  2024-01-23  1:16     ` Pedro Tammela
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2024-01-23  0:43 UTC (permalink / raw)
  To: Pedro Tammela; +Cc: netdev

On Mon, 22 Jan 2024 18:05:45 -0300
Pedro Tammela <pctammela@mojatatu.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@mojatatu.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) {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2 1/2] color: use empty format string instead of NULL in vfprintf
  2024-01-23  0:43   ` Stephen Hemminger
@ 2024-01-23  1:16     ` Pedro Tammela
  0 siblings, 0 replies; 5+ messages in thread
From: Pedro Tammela @ 2024-01-23  1:16 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On 22/01/2024 21:43, Stephen Hemminger wrote:
> On Mon, 22 Jan 2024 18:05:45 -0300
> Pedro Tammela <pctammela@mojatatu.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@mojatatu.com>
>> ---
>>   lib/color.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Wouldn't it be simpler to just add a short circuit check.

Agreed

> This would fix the color case as well.
I missed that one, thanks for catching it!


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-23  1:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22 21:05 [PATCH iproute2 0/2] some musl fixes Pedro Tammela
2024-01-22 21:05 ` [PATCH iproute2 1/2] color: use empty format string instead of NULL in vfprintf Pedro Tammela
2024-01-23  0:43   ` Stephen Hemminger
2024-01-23  1:16     ` Pedro Tammela
2024-01-22 21:05 ` [PATCH iproute2 2/2] bpf: include libgen.h for basename Pedro Tammela

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox