don't call dlsym() from close() hook

it turned out that calling dlsym() may call malloc() in turn,
so we end up with the same deadlock described in the latest commit.

we thus now put all the fds passed to close pre-init into a list
and close them at init time.

this may finally fix #119.
pull/124/head
rofl0r 2016-05-26 19:01:14 +01:00
parent 8870140ff0
commit f1e5f2ba01
1 changed files with 10 additions and 2 deletions

View File

@ -110,6 +110,9 @@ static void setup_hooks(void) {
SETUP_SYM(close);
}
static int close_fds[16];
static int close_fds_cnt = 0;
static void do_init(void) {
srand(time(NULL));
core_initialize();
@ -123,6 +126,8 @@ static void do_init(void) {
setup_hooks();
while(close_fds_cnt) true_close(close_fds[--close_fds_cnt]);
init_l = 1;
}
@ -305,14 +310,17 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
int close(int fd) {
if(!init_l) {
SETUP_SYM(close);
return true_close(fd);
if(close_fds_cnt>=(sizeof close_fds/sizeof close_fds[0])) goto err;
close_fds[close_fds_cnt++] = fd;
errno = 0;
return 0;
}
/* prevent rude programs (like ssh) from closing our pipes */
if(fd != req_pipefd[0] && fd != req_pipefd[1] &&
fd != resp_pipefd[0] && fd != resp_pipefd[1]) {
return true_close(fd);
}
err:
errno = EBADF;
return -1;
}