From d9341a8c746efbb3ce25f5e7f255a4919df16f0a Mon Sep 17 00:00:00 2001 From: Adam Hamsik Date: Thu, 26 Jan 2012 15:17:12 +0100 Subject: [PATCH] Add some more code checking to CCFLAGS, remove unnecessary ifdef's --- Makefile | 6 ++--- src/core.h | 1 - src/libproxychains.c | 62 +++++++++++++++++++------------------------- src/main.c | 6 ++++- 4 files changed, 35 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index e64de83..3055b1d 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ SRCS = $(sort $(wildcard src/*.c)) OBJS = $(SRCS:.c=.o) LOBJS = src/core.o src/libproxychains.o -CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE +CCFLAGS = -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror -Wextra LDFLAGS = -shared -fPIC -ldl -lpthread INC = PIC = -fPIC @@ -32,7 +32,7 @@ ALL_TOOLS = $(PXCHAINS) -include config.mak -CFLAGS+=$(USER_CFLAGS) +CCFLAGS+=$(USER_CFLAGS) CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" @@ -50,7 +50,7 @@ clean: rm -f $(OBJS) %.o: %.c - $(CC) $(CFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $< + $(CC) $(CCFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $< $(LDSO_PATHNAME): $(LOBJS) $(CC) $(LDFLAGS) -Wl,-soname=$(LDSO_PATHNAME) -o $@ $(LOBJS) diff --git a/src/core.h b/src/core.h index 1ec41c5..ae57dc5 100644 --- a/src/core.h +++ b/src/core.h @@ -112,7 +112,6 @@ int connect_proxy_chain ( int proxychains_write_log(char *str,...); struct hostent* proxy_gethostbyname(const char *name); - typedef int (*connect_t)(int, const struct sockaddr *, socklen_t); connect_t true_connect; diff --git a/src/libproxychains.c b/src/libproxychains.c index a71b3b0..0434a0e 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -18,20 +18,21 @@ #undef _GNU_SOURCE #define _GNU_SOURCE +#include +#include + +#include +#include +#include +#include #include -#include #include #include -#include -#include +#include #include #include -#include #include -#include -#include - #include "core.h" #include "common.h" @@ -45,21 +46,27 @@ int tcp_read_time_out; int tcp_connect_time_out; -chain_type proxychains_ct; -proxy_data proxychains_pd[MAX_CHAIN]; -unsigned int proxychains_proxy_count = 0; int proxychains_got_chain_data = 0; -unsigned int proxychains_max_chain = 1; int proxychains_quiet_mode = 0; int proxychains_resolver = 0; static int init_l = 0; + +unsigned int proxychains_proxy_count = 0; +unsigned int proxychains_max_chain = 1; + localaddr_arg localnet_addr[MAX_LOCALNET]; +chain_type proxychains_ct; +proxy_data proxychains_pd[MAX_CHAIN]; + size_t num_localnet_addr = 0; static inline void get_chain_data(proxy_data *pd, unsigned int *proxy_count, chain_type *ct); static void init_lib(void); +/* + * Initialize libproxychains. + */ static void init_lib(void) { #ifdef THREAD_SAFE @@ -76,16 +83,12 @@ static void init_lib(void) fprintf(stderr, "Cannot load symbol 'connect' %s\n", dlerror()); exit(1); } else { - #ifdef DEBUG - PDEBUG( "loaded symbol 'connect'" - " real addr %p wrapped addr %p\n", - true_connect, connect); - #endif + PDEBUG( "loaded symbol 'connect' real addr %p wrapped addr %p\n", + true_connect, connect); } + if(connect==true_connect) { - #ifdef DEBUG PDEBUG("circular reference detected, aborting!\n"); - #endif abort(); } @@ -97,11 +100,9 @@ static void init_lib(void) dlerror()); exit(1); } else { - #ifdef DEBUG PDEBUG( "loaded symbol 'gethostbyname'" - " real addr %p wrapped addr %p\n", - true_gethostbyname, gethostbyname); - #endif + " real addr %p wrapped addr %p\n", + true_gethostbyname, gethostbyname); } true_getaddrinfo = (getaddrinfo_t) dlsym(RTLD_NEXT, "getaddrinfo"); @@ -111,11 +112,9 @@ static void init_lib(void) dlerror()); exit(1); } else { - #ifdef DEBUG PDEBUG( "loaded symbol 'getaddrinfo'" " real addr %p wrapped addr %p\n", true_getaddrinfo, getaddrinfo); - #endif } true_freeaddrinfo = (freeaddrinfo_t) dlsym(RTLD_NEXT, "freeaddrinfo"); @@ -125,11 +124,9 @@ static void init_lib(void) dlerror()); exit(1); } else { - #ifdef DEBUG PDEBUG( "loaded symbol 'freeaddrinfo'" " real addr %p wrapped addr %p\n", true_freeaddrinfo, freeaddrinfo); - #endif } true_gethostbyaddr = (gethostbyaddr_t) dlsym(RTLD_NEXT, "gethostbyaddr"); @@ -139,11 +136,9 @@ static void init_lib(void) dlerror()); exit(1); } else { - #ifdef DEBUG PDEBUG( "loaded symbol 'gethostbyaddr'" " real addr %p wrapped addr %p\n", true_gethostbyaddr, gethostbyaddr); - #endif } true_getnameinfo = (getnameinfo_t) dlsym(RTLD_NEXT, "getnameinfo"); @@ -153,11 +148,9 @@ static void init_lib(void) dlerror()); exit(1); } else { - #ifdef DEBUG PDEBUG( "loaded symbol 'getnameinfo'" " real addr %p wrapped addr %p\n", true_getnameinfo, getnameinfo); - #endif } init_l = 1; } @@ -254,10 +247,10 @@ static inline void get_chain_data( if (sscanf(local_in_addr_port, "%15[^:]:%5s", local_in_addr, local_in_port) < 2) { - PDEBUG("added localnet: netaddr=%s, port=%s\n", - local_in_addr, local_netmask); + PDEBUG("added localnet: netaddr=%s, port=%s\n", + local_in_addr, local_netmask); } else { - PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n", + PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n", local_in_addr, local_in_port, local_netmask); } if (num_localnet_addr < MAX_LOCALNET) @@ -306,7 +299,7 @@ static inline void get_chain_data( -int connect (int sock, const struct sockaddr *addr, unsigned int len) +int connect (int sock, const struct sockaddr *addr, socklen_t len) { int socktype=0, flags=0, ret=0; socklen_t optlen = 0; @@ -501,4 +494,3 @@ struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type) } return NULL; } - diff --git a/src/main.c b/src/main.c index aad499c..1dc5403 100644 --- a/src/main.c +++ b/src/main.c @@ -18,12 +18,15 @@ #define _POSIX_C_SOURCE 200809L #undef _XOPEN_SOURCE #define _XOPEN_SOURCE 700 + +#include +#include + #include #include #include #include #include -#include #include extern char *optarg; @@ -45,6 +48,7 @@ int check_path(char* path) { return access(path, R_OK) != -1; } +/* XXX This shouldn't be defined here */ static const char* dll_name = "libproxychains4.so"; static char own_dir[256];