[PATCH] kmod/depmod: explicitly include the header for basename()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hello list,

(Please Cc: me on the replies.)

 Recent versions of the musl libc declare basename() (and dirname())
exclusively in <libgen.h>, as specified by POSIX. If this header is
not properly included, when building kmod with musl, basename() is an
unknown symbol and will be assumed as returning int, which causes
problems as soon as kmod performs a printf("%s", basename(argv[0])),
e.g. in kmod_help(). (On x86_64, int is 32 bit, so the pointer address
is truncated, which causes a segfault on access.)

 Simply including libgen.h wherever basename() is used, i.e. depmod.c
and kmod.c, fixes the issue. It will print warnings because you store
the result in a const char *, but these are harmless and can be fixed
later.

 None of the kmod files seems to use dirname(), but several of them use
dirname as a symbol, including depmod.c, where it will shadow the libc's
dirname symbol. This does not cause a problem right now, but it might be
a good idea to rename the dirname variables at some point.


diff -rNU3 kmod-32.old/tools/depmod.c kmod-32/tools/depmod.c
--- kmod-32.old/tools/depmod.c  2023-12-06 16:34:31.000000000 +0100
+++ kmod-32/tools/depmod.c      2024-04-08 20:55:03.998592078 +0200
@@ -22,6 +22,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <getopt.h>
+#include <libgen.h>
 #include <limits.h>
 #include <regex.h>
 #include <stdio.h>
diff -rNU3 kmod-32.old/tools/kmod.c kmod-32/tools/kmod.c
--- kmod-32.old/tools/kmod.c    2024-02-20 23:10:55.000000000 +0100
+++ kmod-32/tools/kmod.c        2024-04-08 21:55:03.888577992 +0200
@@ -19,6 +19,7 @@

 #include <errno.h>
 #include <getopt.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>






[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux