mirror of
				https://github.com/rofl0r/proxychains-ng.git
				synced 2025-11-04 00:56:03 +00:00 
			
		
		
		
	put a mutex lock around gethostent() usage, to prevent internal
races. the external usage was covered by the latest commit.
This commit is contained in:
		@@ -37,6 +37,7 @@
 | 
				
			|||||||
#ifdef THREAD_SAFE
 | 
					#ifdef THREAD_SAFE
 | 
				
			||||||
#include <pthread.h>
 | 
					#include <pthread.h>
 | 
				
			||||||
pthread_mutex_t internal_ips_lock;
 | 
					pthread_mutex_t internal_ips_lock;
 | 
				
			||||||
 | 
					pthread_mutex_t hostdb_lock;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "core.h"
 | 
					#include "core.h"
 | 
				
			||||||
@@ -774,11 +775,14 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data*
 | 
				
			|||||||
	memset(buff, 0, sizeof(buff));
 | 
						memset(buff, 0, sizeof(buff));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// this iterates over the "known hosts" db, usually /etc/hosts
 | 
						// this iterates over the "known hosts" db, usually /etc/hosts
 | 
				
			||||||
 | 
						MUTEX_LOCK(&hostdb_lock);
 | 
				
			||||||
	while((hp = gethostent()))
 | 
						while((hp = gethostent()))
 | 
				
			||||||
		if(!strcmp(hp->h_name, name) && hp->h_addrtype == AF_INET && hp->h_length == sizeof(in_addr_t)) {
 | 
							if(!strcmp(hp->h_name, name) && hp->h_addrtype == AF_INET && hp->h_length == sizeof(in_addr_t)) {
 | 
				
			||||||
			data->resolved_addr = *((in_addr_t*)(hp->h_addr_list[0]));
 | 
								data->resolved_addr = *((in_addr_t*)(hp->h_addr_list[0]));
 | 
				
			||||||
 | 
								MUTEX_UNLOCK(&hostdb_lock);
 | 
				
			||||||
			goto retname;
 | 
								goto retname;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						MUTEX_UNLOCK(&hostdb_lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hash = dalias_hash((char *) name);
 | 
						hash = dalias_hash((char *) name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,6 +45,7 @@ extern internal_ip_lookup_table internal_ips;
 | 
				
			|||||||
#ifdef THREAD_SAFE
 | 
					#ifdef THREAD_SAFE
 | 
				
			||||||
#include <pthread.h>
 | 
					#include <pthread.h>
 | 
				
			||||||
extern pthread_mutex_t internal_ips_lock;
 | 
					extern pthread_mutex_t internal_ips_lock;
 | 
				
			||||||
 | 
					extern pthread_mutex_t hostdb_lock;
 | 
				
			||||||
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
 | 
					# define MUTEX_LOCK(x) pthread_mutex_lock(x)
 | 
				
			||||||
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
 | 
					# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
 | 
				
			||||||
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
 | 
					# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -93,6 +93,7 @@ static void* load_sym(char* symname, void* proxyfunc) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void do_init(void) {
 | 
					static void do_init(void) {
 | 
				
			||||||
	MUTEX_INIT(&internal_ips_lock, NULL);
 | 
						MUTEX_INIT(&internal_ips_lock, NULL);
 | 
				
			||||||
 | 
						MUTEX_INIT(&hostdb_lock, NULL);
 | 
				
			||||||
	/* read the config file */
 | 
						/* read the config file */
 | 
				
			||||||
	get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
 | 
						get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user