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:
rofl0r
2012-11-04 05:23:51 +01:00
parent 8ce1e51a60
commit e05cafc8e2
3 changed files with 6 additions and 0 deletions

View File

@ -37,6 +37,7 @@
#ifdef THREAD_SAFE
#include <pthread.h>
pthread_mutex_t internal_ips_lock;
pthread_mutex_t hostdb_lock;
#endif
#include "core.h"
@ -774,11 +775,14 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data*
memset(buff, 0, sizeof(buff));
// this iterates over the "known hosts" db, usually /etc/hosts
MUTEX_LOCK(&hostdb_lock);
while((hp = gethostent()))
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]));
MUTEX_UNLOCK(&hostdb_lock);
goto retname;
}
MUTEX_UNLOCK(&hostdb_lock);
hash = dalias_hash((char *) name);