mirror of
https://github.com/rofl0r/proxychains-ng
synced 2025-01-08 22:22:52 +08:00
Changed calls to close, sendto, recvfrom to calls to true_XX calls to
avoid some deadlocks
This commit is contained in:
parent
7e818c1499
commit
2eb03d3719
@ -352,9 +352,9 @@ void at_close(void) {
|
||||
const int msg = ATM_EXIT;
|
||||
true_write(req_pipefd[1], &msg, sizeof(int));
|
||||
pthread_join(allocator_thread, NULL);
|
||||
close(req_pipefd[0]);
|
||||
close(req_pipefd[1]);
|
||||
close(resp_pipefd[0]);
|
||||
close(resp_pipefd[1]);
|
||||
true_close(req_pipefd[0]);
|
||||
true_close(req_pipefd[1]);
|
||||
true_close(resp_pipefd[0]);
|
||||
true_close(resp_pipefd[1]);
|
||||
MUTEX_DESTROY(internal_ips_lock);
|
||||
}
|
||||
|
24
src/core.c
24
src/core.c
@ -1063,7 +1063,7 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
||||
if(!inet_ntop(v6?AF_INET6:AF_INET,pto->ip.addr.v6,ip_buf,sizeof ip_buf)) {
|
||||
pto->ps = DOWN_STATE;
|
||||
proxychains_write_log("<--ip conversion error!\n");
|
||||
close(ns);
|
||||
true_close(ns);
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
hostname = ip_buf;
|
||||
@ -1078,12 +1078,12 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
||||
case BLOCKED:
|
||||
pto->ps = BLOCKED_STATE;
|
||||
proxychains_write_log("<--denied\n");
|
||||
close(ns);
|
||||
true_close(ns);
|
||||
break;
|
||||
case SOCKET_ERROR:
|
||||
pto->ps = DOWN_STATE;
|
||||
proxychains_write_log("<--socket error or timeout!\n");
|
||||
close(ns);
|
||||
true_close(ns);
|
||||
break;
|
||||
}
|
||||
return retcode;
|
||||
@ -1240,11 +1240,11 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
||||
|
||||
proxychains_write_log(TP " OK\n");
|
||||
dup2(ns, sock);
|
||||
close(ns);
|
||||
true_close(ns);
|
||||
return 0;
|
||||
error:
|
||||
if(ns != -1)
|
||||
close(ns);
|
||||
true_close(ns);
|
||||
errno = ECONNREFUSED; // for nmap ;)
|
||||
return -1;
|
||||
|
||||
@ -1255,7 +1255,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
||||
|
||||
release_all(pd, proxy_count);
|
||||
if(ns != -1)
|
||||
close(ns);
|
||||
true_close(ns);
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
@ -1612,9 +1612,9 @@ struct hostent* proxy_gethostbyname_old(const char *name)
|
||||
|
||||
case 0: // child
|
||||
proxychains_write_log("|DNS-request| %s \n", name);
|
||||
close(pipe_fd[0]);
|
||||
true_close(pipe_fd[0]);
|
||||
dup2(pipe_fd[1],1);
|
||||
close(pipe_fd[1]);
|
||||
true_close(pipe_fd[1]);
|
||||
|
||||
// putenv("LD_PRELOAD=");
|
||||
execlp("proxyresolv","proxyresolv",name,NULL);
|
||||
@ -1622,17 +1622,17 @@ struct hostent* proxy_gethostbyname_old(const char *name)
|
||||
exit(2);
|
||||
|
||||
case -1: //error
|
||||
close(pipe_fd[0]);
|
||||
close(pipe_fd[1]);
|
||||
true_close(pipe_fd[0]);
|
||||
true_close(pipe_fd[1]);
|
||||
perror("can't fork");
|
||||
goto err;
|
||||
|
||||
default:
|
||||
close(pipe_fd[1]);
|
||||
true_close(pipe_fd[1]);
|
||||
waitpid(pid, &status, 0);
|
||||
buff[0] = 0;
|
||||
true_read(pipe_fd[0],&buff,sizeof(buff));
|
||||
close(pipe_fd[0]);
|
||||
true_close(pipe_fd[0]);
|
||||
got_buff:
|
||||
l = strlen(buff);
|
||||
if (!l) goto err_dns;
|
||||
|
12
src/rdns.c
12
src/rdns.c
@ -22,9 +22,9 @@ size_t rdns_daemon_get_host_for_ip(ip_type4 ip, char* readbuf) {
|
||||
.m.ip = ip,
|
||||
};
|
||||
int fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);
|
||||
sendto(fd, &msg, sizeof(msg.h)+4, 0, (void*)&rdns_server, sizeof(rdns_server));
|
||||
recvfrom(fd, &msg, sizeof msg, 0, (void*)0, (void*)0);
|
||||
close(fd);
|
||||
true_sendto(fd, &msg, sizeof(msg.h)+4, 0, (void*)&rdns_server, sizeof(rdns_server));
|
||||
true_recvfrom(fd, &msg, sizeof msg, 0, (void*)0, (void*)0);
|
||||
true_close(fd);
|
||||
msg.h.datalen = ntohs(msg.h.datalen);
|
||||
if(!msg.h.datalen || msg.h.datalen > 256) return 0;
|
||||
memcpy(readbuf, msg.m.host, msg.h.datalen);
|
||||
@ -39,9 +39,9 @@ static ip_type4 rdns_daemon_get_ip_for_host(char* host, size_t len) {
|
||||
memcpy(msg.m.host, host, len+1);
|
||||
msg.h.datalen = htons(len+1);
|
||||
int fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);
|
||||
sendto(fd, &msg, sizeof(msg.h)+len+1, 0, (void*)&rdns_server, sizeof(rdns_server));
|
||||
recvfrom(fd, &msg, sizeof msg, 0, (void*)0, (void*)0);
|
||||
close(fd);
|
||||
true_sendto(fd, &msg, sizeof(msg.h)+len+1, 0, (void*)&rdns_server, sizeof(rdns_server));
|
||||
true_recvfrom(fd, &msg, sizeof msg, 0, (void*)0, (void*)0);
|
||||
true_close(fd);
|
||||
if(ntohs(msg.h.datalen) != 4) return IPT4_INT(-1);
|
||||
return msg.m.ip;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user