Skip to content

Commit

Permalink
Hook realpath(3) for /proc/self/exe
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Oct 8, 2024
1 parent d7f8257 commit ec6de7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CC ?= clang
TERMUX_BASE_DIR ?= /data/data/com.termux/files
CFLAGS += -Wall -Wextra -Werror -Wshadow -fvisibility=hidden -std=c17
C_SOURCE := src/termux-exec.c src/exec-variants.c src/termux-readlink.c
C_SOURCE := src/termux-exec.c src/exec-variants.c src/termux-readlink.c src/termux-realpath.c
CLANG_FORMAT := clang-format --sort-includes --style="{ColumnLimit: 120}" $(C_SOURCE) tests/fexecve.c tests/system-uname.c tests/print-argv0.c tests/popen.c
CLANG_TIDY ?= clang-tidy

Expand Down
21 changes: 21 additions & 0 deletions src/termux-realpath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>

__attribute__((visibility("default"))) char* _Nullable realpath(const char* _Nonnull path, char* _Nullable resolved) {
char* (*orig_realpath)(const char*, char*);
orig_realpath = dlsym(RTLD_NEXT, "realpath");

if (strcmp(path, "/proc/self/exe") == 0) {
const char *termux_self_exe = getenv("TERMUX_EXEC__PROC_SELF_EXE");
if (termux_self_exe) {
path = termux_self_exe;
}
}

return orig_realpath(path, resolved);
}

0 comments on commit ec6de7a

Please sign in to comment.