summaryrefslogtreecommitdiffstats
path: root/tools/bpf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@kernel.org>2024-01-29 15:33:26 +0100
committerDaniel Borkmann <daniel@iogearbox.net>2024-01-29 16:08:46 +0100
commit29788f39a4171dd48a6d19eb78cf2ab168c4349a (patch)
treed072aec607a6d5fa0825e542e00f11a9e9fdef95 /tools/bpf
parentnet: free altname using an RCU callback (diff)
downloadlinux-29788f39a4171dd48a6d19eb78cf2ab168c4349a.tar.xz
linux-29788f39a4171dd48a6d19eb78cf2ab168c4349a.zip
bpftool: Be more portable by using POSIX's basename()
musl libc had the basename() prototype in string.h, but this is a glibc-ism, now they removed the _GNU_SOURCE bits in their devel distro, Alpine Linux edge: https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 So lets use the POSIX version, the whole rationale is spelled out at: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Jiri Olsa <olsajiri@gmail.com> Acked-by: Quentin Monnet <quentin@isovalent.com> Link: https://lore.kernel.org/lkml/ZZhsPs00TI75RdAr@kernel.org Link: https://lore.kernel.org/bpf/Zbe3NuOgaupvUcpF@kernel.org
Diffstat (limited to 'tools/bpf')
-rw-r--r--tools/bpf/bpftool/gen.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index ee3ce2b8000d..a9334c57e859 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -7,6 +7,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <libgen.h>
#include <linux/err.h>
#include <stdbool.h>
#include <stdio.h>
@@ -56,9 +57,11 @@ static bool str_has_suffix(const char *str, const char *suffix)
static void get_obj_name(char *name, const char *file)
{
- /* Using basename() GNU version which doesn't modify arg. */
- strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
- name[MAX_OBJ_NAME_LEN - 1] = '\0';
+ char file_copy[PATH_MAX];
+
+ /* Using basename() POSIX version to be more portable. */
+ strncpy(file_copy, file, PATH_MAX - 1)[PATH_MAX - 1] = '\0';
+ strncpy(name, basename(file_copy), MAX_OBJ_NAME_LEN - 1)[MAX_OBJ_NAME_LEN - 1] = '\0';
if (str_has_suffix(name, ".o"))
name[strlen(name) - 2] = '\0';
sanitize_identifier(name);