From ce4c71078eb2a327408926f9bd9e98df6128b476 Mon Sep 17 00:00:00 2001 From: crass Date: Sat, 1 Sep 2018 05:12:42 -0500 Subject: [PATCH 1/3] Fixes issue #256. If config path in envvar is not absolute, make it so. --- src/common.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common.c b/src/common.c index c126ecf..f45a6fd 100644 --- a/src/common.c +++ b/src/common.c @@ -1,4 +1,5 @@ #include "common.h" +#include "debug.h" #include #include #include @@ -94,5 +95,11 @@ char *get_config_path(char* default_path, char* pbuf, size_t bufsize) { return NULL; have: + if(path[0] != '/') { + path = realpath(path, NULL); + setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1); + free(path); + path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR); + } return path; } From 369f92670ceda75bbeb8e08b457d9aa05529543d Mon Sep 17 00:00:00 2001 From: crass Date: Sat, 1 Sep 2018 05:16:37 -0500 Subject: [PATCH 2/3] 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. --- src/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index acda4be..002a909 100644 --- a/src/main.c +++ b/src/main.c @@ -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); + snprintf(pbuf, sizeof(pbuf), "%s", path); + free(path); + path = pbuf; + } + #ifdef IS_MAC putenv("DYLD_FORCE_FLAT_NAMESPACE=1"); #define LD_PRELOAD_ENV "DYLD_INSERT_LIBRARIES" @@ -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 : ""); From f7efb1ecbebd52a60e228a1984face7cbf19e7ed Mon Sep 17 00:00:00 2001 From: crass Date: Sat, 1 Sep 2018 05:18:13 -0500 Subject: [PATCH 3/3] Make all PDEBUG calls print the PID, helpful for multiprocess applications. --- src/debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug.h b/src/debug.h index b9b5215..4e65f50 100644 --- a/src/debug.h +++ b/src/debug.h @@ -4,7 +4,7 @@ #ifdef DEBUG # include # define PSTDERR(fmt, args...) do { dprintf(2,fmt, ## args); } while(0) -# define PDEBUG(fmt, args...) PSTDERR("DEBUG:"fmt, ## args) +# define PDEBUG(fmt, args...) PSTDERR("DEBUG:pid[%d]:"fmt, getpid(), ## args) # define DEBUGDECL(args...) args # include "core.h"