Skip to content

Commit 369f926

Browse files
author
crass
committed
Make sure preload library path is absolute. This fixes issues where a chdir is followed by a process fork, which can cause the library to not be found.
1 parent ce4c710 commit 369f926

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ int main(int argc, char *argv[]) {
131131
if(!quiet)
132132
fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
133133

134+
snprintf(path=pbuf, sizeof(pbuf), "%s/%s", prefix, dll_name);
135+
if (path[0] != '/'){
136+
path = realpath(path, NULL);
137+
snprintf(pbuf, sizeof(pbuf), "%s", path);
138+
free(path);
139+
path = pbuf;
140+
}
141+
134142
#ifdef IS_MAC
135143
putenv("DYLD_FORCE_FLAT_NAMESPACE=1");
136144
#define LD_PRELOAD_ENV "DYLD_INSERT_LIBRARIES"
@@ -143,8 +151,8 @@ int main(int argc, char *argv[]) {
143151
#define LD_PRELOAD_SEP " "
144152
#endif
145153
char *old_val = getenv(LD_PRELOAD_ENV);
146-
snprintf(buf, sizeof(buf), LD_PRELOAD_ENV "=%s/%s%s%s",
147-
prefix, dll_name,
154+
snprintf(buf, sizeof(buf), LD_PRELOAD_ENV "=%s%s%s",
155+
path,
148156
/* append previous LD_PRELOAD content, if existent */
149157
old_val ? LD_PRELOAD_SEP : "",
150158
old_val ? old_val : "");

0 commit comments

Comments
 (0)