Skip to content

Commit

Permalink
Fix crash in bogus OOM handling while TCP async in enabled.
Browse files Browse the repository at this point in the history
The async support assums the c->async exists all the time, so error if we cannot alloc the c->async struct while creating a new TCP conn

(cherry picked from commit 0b270ad)
  • Loading branch information
bogdan-iancu committed Aug 17, 2022
1 parent 5dc2ec7 commit e5377a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions net/net_tcp.c
Expand Up @@ -898,8 +898,10 @@ static struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
c->async->allocated = protos[si->proto].net.async_chunks;
c->async->oldest = 0;
c->async->pending = 0;
} else
LM_WARN("could not allocate async data for con!\n");
} else {
LM_ERR("could not allocate async data for con!\n");
goto error;
}
}

tcp_connections_no++;
Expand Down
7 changes: 6 additions & 1 deletion net/proto_tcp/proto_tcp.c
Expand Up @@ -217,8 +217,13 @@ static int proto_tcp_init(struct proto_info *pi)
}

/* without async support, there is nothing to init/clean per conn */
if (tcp_async!=0)
if (tcp_async!=0) {
/* be sure the settings are consistent, like having a minimum 2 value
* if the tcp_async is enbled */
if (tcp_async_max_postponed_chunks<=1)
tcp_async_max_postponed_chunks = 2;
pi->net.async_chunks= tcp_async_max_postponed_chunks;
}

return 0;
}
Expand Down

0 comments on commit e5377a6

Please sign in to comment.