From e2cd35e48dea40d8c2e3060474d645d6d2aa1d52 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 3 Jan 2025 08:52:39 +0000 Subject: [PATCH] build: Require ELF interpreters Signed-off-by: Michael Tremer --- src/pakfire/build.c | 49 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/pakfire/build.c b/src/pakfire/build.c index 5e5563da5..57ba341ab 100644 --- a/src/pakfire/build.c +++ b/src/pakfire/build.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -613,10 +614,45 @@ ERROR: return r; } +static int pakfire_build_find_elf_requires( + struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) { + struct pakfire_elf* elf = NULL; + int r; + + // Try to open the ELF file + r = pakfire_elf_open_file(&elf, ctx, file); + if (r < 0) { + switch (-r) { + // This does not seem to be an ELF file + case ENOTSUP: + return 0; + + // Raise any other errors + default: + goto ERROR; + } + } + + // Fetch the interpreter + const char* interpreter = pakfire_elf_interpreter(elf); + if (interpreter) { + r = pakfire_package_add_dep(deps->pkg, PAKFIRE_PKG_REQUIRES, "%s", interpreter); + if (r < 0) + goto ERROR; + } + +ERROR: + if (elf) + pakfire_elf_unref(elf); + + return r; +} + static int __pakfire_build_find_requires( struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { struct pakfire_find_deps_ctx* deps = data; const char* path = NULL; + int r; // Fetch the file path path = pakfire_file_get_path(file); @@ -632,9 +668,20 @@ static int __pakfire_build_find_requires( return 0; // Handle pkg-config files - if (pakfire_path_match("**.pc", path)) + else if (pakfire_path_match("**.pc", path)) return pakfire_build_find_pkgconfig_requires(ctx, file, deps); + // Split certain file types differently + switch (pakfire_file_get_type(file)) { + // Regular files + case S_IFREG: + // Handle ELF files + r = pakfire_build_find_elf_requires(ctx, file, deps); + if (r < 0) + return r; + break; + } + return 0; } -- 2.47.2