From c6a768c12ce7e83631d08f53937a075c4f76e2d5 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 12 Aug 2019 11:10:15 +0200 Subject: use LD_LIBRARY_PATH for glibc instead of calling its loader Calling the loader fails on non ELF executables. Exec, formerly run_cmd, now takes two options: -l LD_LIBRARY_PATH, -p LD_PRELOAD. -p sets LD_PRELOAD and -l LD_LIBRARY_PATH before executing the rest of argv. glibc no longer uses cmd_prefix in favor of LD_LIBRARY_PATH. --- src/exec.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/exec.c (limited to 'src/exec.c') diff --git a/src/exec.c b/src/exec.c new file mode 100644 index 0000000..37ef5b6 --- /dev/null +++ b/src/exec.c @@ -0,0 +1,32 @@ +#define _GNU_SOURCE +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + if (argc < 3) { + printf("Usage: %s [-p LD_PRELOAD] [-l LD_LIBRARY_PATH] [cmd args]\n"); + printf("\tset LD_PRELOAD to ld_preload and call execvp [cmd args]\n"); + return 1; + } + + int i = 1; + for (; i < argc; i++) { + // Overwrite LD_PRELOAD. + if (strncmp(argv[i], "-p", 2) == 0) { + setenv("LD_PRELOAD", argv[i+1], 1); + i++; + // Overwrite LD_LIBRARY_PATH. + } else if (strncmp(argv[i], "-l", 2) == 0) { + setenv("LD_LIBRARY_PATH", argv[i+1], 1); + i++; + } else { + break; + } + } + + + // Run cmd. + execvp(argv[i], &argv[i]); +} -- cgit v1.2.3