mirror of
https://github.com/rofl0r/proxychains-ng
synced 2025-02-09 14:43:26 +08:00
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.
This commit is contained in:
parent
53c6c2ca9b
commit
2182eff358
4
Makefile
4
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
|
||||
|
@ -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;
|
||||
|
@ -37,7 +37,6 @@
|
||||
|
||||
#include "core.h"
|
||||
#include "common.h"
|
||||
#include "shm.h"
|
||||
#include "allocator_thread.h"
|
||||
|
||||
extern int tcp_read_time_out;
|
||||
|
@ -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();
|
||||
|
||||
|
53
src/shm.c
53
src/shm.c
@ -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;
|
||||
}
|
17
src/shm.h
17
src/shm.h
@ -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
|
@ -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);
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue
Block a user