Skip to content

Commit

Permalink
net/tcp: save fd before sending the conn to main
Browse files Browse the repository at this point in the history
Save local fd of the connection before sending it to TCP main, to make
sure we it won't get overwritten by main, and we close somebody else's
file descriptor.
  • Loading branch information
razvancrainea committed Feb 8, 2019
1 parent 939213d commit ed4e862
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions net/net_tcp.c
Expand Up @@ -933,18 +933,20 @@ struct tcp_connection* tcp_conn_new(int sock, union sockaddr_union* su,
int tcp_conn_send(struct tcp_connection *c)
{
long response[2];
int n;
int n, fd;

/* inform TCP main about this new connection */
if (c->state==S_CONN_CONNECTING) {
/* store the local fd now, before TCP main overwrites it */
fd = c->s;
response[0]=(long)c;
response[1]=ASYNC_CONNECT;
n=send_fd(unix_tcp_sock, response, sizeof(response), c->s);
n=send_fd(unix_tcp_sock, response, sizeof(response), fd);
if (n<=0) {
LM_ERR("Failed to send the socket to main for async connection\n");
goto error;
}
close(c->s);
close(fd);
} else {
response[0]=(long)c;
response[1]=CONN_NEW;
Expand Down

2 comments on commit ed4e862

@AnjanIpc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone tell me, which version, it is fixed ??

@AnjanIpc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its bit urgent to know the fixed version number.
Can you please let me know, which version, it is fixed ??

Please sign in to comment.