Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rofl0r/proxychains-ng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrofl0r <retnyg@gmx.net>2015-06-06 13:41:36 +0300
committerrofl0r <retnyg@gmx.net>2015-06-06 13:43:53 +0300
commit2182eff3584b1e4a3660c69393baf338cf4841be (patch)
tree6af25dc8e52b709e51060e442e9d716b855f6506
parent53c6c2ca9bbb3fc11af7731b206a52c0a9391348 (diff)
fix segfault in DNS mapping lookup code
the allocatorthread got pointers to RAM which were reallocated behind the back, and if realloc() couldn't grow in-place, lead to segfaults in applications that do a lot of DNS-lookups such as webbrowsers. closes #66 closes #31 thanks to @ravomavain for tracking down the issue.
-rw-r--r--Makefile4
-rw-r--r--src/allocator_thread.c8
-rw-r--r--src/core.c1
-rw-r--r--src/libproxychains.c3
-rw-r--r--src/shm.c53
-rw-r--r--src/shm.h17
-rw-r--r--src/stringdump.c13
-rw-r--r--src/stringdump.h12
8 files changed, 8 insertions, 103 deletions
diff --git a/Makefile b/Makefile
index 3cacaa9..e2f3e23 100644
--- a/Makefile
+++ b/Makefile
@@ -16,8 +16,8 @@ sysconfdir=$(prefix)/etc
SRCS = $(sort $(wildcard src/*.c))
OBJS = $(SRCS:.c=.o)
LOBJS = src/nameinfo.o src/version.o \
- src/core.o src/common.o src/libproxychains.o src/shm.o \
- src/allocator_thread.o src/ip_type.o src/stringdump.o \
+ src/core.o src/common.o src/libproxychains.o \
+ src/allocator_thread.o src/ip_type.o \
src/hostsreader.o src/hash.o src/debug.o
GENH = src/version.h
diff --git a/src/allocator_thread.c b/src/allocator_thread.c
index 5ed6b13..12130b5 100644
--- a/src/allocator_thread.c
+++ b/src/allocator_thread.c
@@ -10,12 +10,10 @@
#include <stddef.h>
#include <errno.h>
#include "allocator_thread.h"
-#include "shm.h"
#include "debug.h"
#include "ip_type.h"
#include "mutex.h"
#include "hash.h"
-#include "stringdump.h"
/* stuff for our internal translation table */
@@ -30,6 +28,12 @@ typedef struct {
string_hash_tuple** list;
} internal_ip_lookup_table;
+static void *dumpstring(char* s, size_t len) {
+ char* p = malloc(len);
+ if(p) memcpy(p, s, len);
+ return p;
+}
+
pthread_mutex_t internal_ips_lock;
internal_ip_lookup_table *internal_ips = NULL;
internal_ip_lookup_table internal_ips_buf;
diff --git a/src/core.c b/src/core.c
index 25483c2..eb05566 100644
--- a/src/core.c
+++ b/src/core.c
@@ -37,7 +37,6 @@
#include "core.h"
#include "common.h"
-#include "shm.h"
#include "allocator_thread.h"
extern int tcp_read_time_out;
diff --git a/src/libproxychains.c b/src/libproxychains.c
index c9eaeaa..9e898b9 100644
--- a/src/libproxychains.c
+++ b/src/libproxychains.c
@@ -95,15 +95,12 @@ static void* load_sym(char* symname, void* proxyfunc) {
#define SETUP_SYM(X) do { true_ ## X = load_sym( # X, X ); } while(0)
-#include "shm.h"
#include "allocator_thread.h"
-#include "stringdump.h"
const char *proxychains_get_version(void);
static void do_init(void) {
srand(time(NULL));
- dumpstring_init(); // global string garbage can
core_initialize();
at_init();
diff --git a/src/shm.c b/src/shm.c
deleted file mode 100644
index d51470a..000000000
--- a/src/shm.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include <assert.h>
-#include <string.h>
-#include <limits.h>
-#include <string.h>
-#include <stdlib.h>
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
-#endif
-#include "shm.h"
-#include "debug.h"
-
-#if 0
-#include <sys/mman.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-
-/* allocates shared memory which can be accessed from the parent and its childs */
-void *shm_realloc(void* old, size_t old_size, size_t new_size) {
- //PFUNC();
- void *nu = mmap(NULL, new_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
- if(old) {
- if(!nu) return NULL;
- assert(new_size >= old_size);
- memcpy(nu, old, old_size);
- munmap(old, old_size);
- }
- return nu;
-}
-#endif
-
-void stringpool_init(struct stringpool* sp) {
- PFUNC();
- memset(sp, 0, sizeof *sp);
-}
-
-char* stringpool_add(struct stringpool *sp, char* s, size_t len) {
- //PFUNC();
- if(len > sp->alloced - sp->used) {
- size_t newsz = sp->used + len;
- size_t inc = PAGE_SIZE - (newsz % PAGE_SIZE);
- newsz += (inc == PAGE_SIZE) ? 0 : inc;
- void* p = realloc(sp->start, newsz);
- if(p) {
- sp->start = p;
- sp->alloced = newsz;
- } else
- return 0;
- }
- char* ret = sp->start + sp->used;
- memcpy(ret, s, len);
- sp->used += len;
- return ret;
-}
diff --git a/src/shm.h b/src/shm.h
deleted file mode 100644
index 13b5249..000000000
--- a/src/shm.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef SHM_H
-#define SHM_H
-#include <unistd.h>
-
-struct stringpool {
- size_t alloced;
- size_t used;
- char* start;
-};
-
-void stringpool_init(struct stringpool* sp);
-char* stringpool_add(struct stringpool *sp, char* s, size_t len);
-#if 0
-void *shm_realloc(void* old, size_t old_size, size_t new_size);
-#endif
-//RcB: DEP "shm.c"
-#endif
diff --git a/src/stringdump.c b/src/stringdump.c
deleted file mode 100644
index ff946f0..000000000
--- a/src/stringdump.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "stringdump.h"
-#include "debug.h"
-
-struct stringpool mem;
-
-char *dumpstring(char* s, size_t len) {
- PFUNC();
- return stringpool_add(&mem, s, len);
-}
-
-void dumpstring_init(void) {
- stringpool_init(&mem);
-}
diff --git a/src/stringdump.h b/src/stringdump.h
deleted file mode 100644
index 4c16d6f..000000000
--- a/src/stringdump.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef STRINGDUMP_H
-#define STRINGDUMP_H
-
-#include "shm.h"
-#include <unistd.h>
-
-char *dumpstring(char* s, size_t len);
-void dumpstring_init(void);
-
-//RcB: DEP "stringdump.h"
-
-#endif