Skip to content

Commit

Permalink
Make sure preload library path is absolute. This fixes issues where a…
Browse files Browse the repository at this point in the history
… chdir is followed by a process fork, which can cause the library to not be found.
  • Loading branch information
crass committed Sep 1, 2018
1 parent ce4c710 commit 428d8c7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ int main(int argc, char *argv[]) {
if(!quiet)
fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);

snprintf(path=pbuf, sizeof(pbuf), "%s/%s", prefix, dll_name);
if (path[0] != '/'){
path = realpath(path, NULL);
strncpy(pbuf, path, sizeof(pbuf));
free(path);
path = pbuf;
}

#ifdef IS_MAC
putenv("DYLD_FORCE_FLAT_NAMESPACE=1");
#define LD_PRELOAD_ENV "DYLD_INSERT_LIBRARIES"
Expand All @@ -143,8 +151,8 @@ int main(int argc, char *argv[]) {
#define LD_PRELOAD_SEP " "
#endif
char *old_val = getenv(LD_PRELOAD_ENV);
snprintf(buf, sizeof(buf), LD_PRELOAD_ENV "=%s/%s%s%s",
prefix, dll_name,
snprintf(buf, sizeof(buf), LD_PRELOAD_ENV "=%s%s%s",
path,
/* append previous LD_PRELOAD content, if existent */
old_val ? LD_PRELOAD_SEP : "",
old_val ? old_val : "");
Expand Down

0 comments on commit 428d8c7

Please sign in to comment.