From a823a080da466e4ca68c2d046bc08b907cc460f9 Mon Sep 17 00:00:00 2001 From: Bogdan-Andrei Iancu Date: Wed, 17 Aug 2022 13:05:36 +0300 Subject: [PATCH] Fix crash in bogus OOM handling while TCP async in enabled. 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 0b270ad04db8081bbb829f89fa515fa0c37698c7) --- net/net_tcp.c | 6 ++++-- net/proto_tcp/proto_tcp.c | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/net/net_tcp.c b/net/net_tcp.c index deae6b8b99c..fff9aab4aec 100644 --- a/net/net_tcp.c +++ b/net/net_tcp.c @@ -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++; diff --git a/net/proto_tcp/proto_tcp.c b/net/proto_tcp/proto_tcp.c index e9b87a73c9c..f6be72a29a9 100644 --- a/net/proto_tcp/proto_tcp.c +++ b/net/proto_tcp/proto_tcp.c @@ -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; }