From afbff6a00842d8d02395a8f793636123319978da Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Thu, 9 Sep 2021 22:20:06 +0300 Subject: [PATCH] b2b_logic: fix possible crash after peer entity is disconnected The crash would happen when a receiving a request and the current entity has no peer. --- modules/b2b_logic/logic.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/b2b_logic/logic.c b/modules/b2b_logic/logic.c index 3d5497c2354..e991dd39fcb 100644 --- a/modules/b2b_logic/logic.c +++ b/modules/b2b_logic/logic.c @@ -2008,7 +2008,7 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, } goto send_usual_request; } else { - if(tuple->state != B2B_NOTDEF_STATE) + if(tuple->state != B2B_NOTDEF_STATE && peer) peer->sdp_type = body->len ? B2BL_SDP_NORMAL : B2BL_SDP_LATE; cur_route_ctx.entity_type = src; @@ -2016,10 +2016,13 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, LM_ERR("Out of pkg memory!\n"); goto error; } - cur_route_ctx.peer_type = peer->type; - if (pkg_str_dup(&cur_route_ctx.peer_key, &peer->key) < 0) { - LM_ERR("Out of pkg memory!\n"); - goto error; + + if (peer) { + cur_route_ctx.peer_type = peer->type; + if (pkg_str_dup(&cur_route_ctx.peer_key, &peer->key) < 0) { + LM_ERR("Out of pkg memory!\n"); + goto error; + } } lock_release(&b2bl_htable[hash_index].lock); @@ -2030,7 +2033,8 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, cur_route_ctx.flags &= ~B2BL_RT_REQ_CTX; pkg_free(cur_route_ctx.entity_key.s); - pkg_free(cur_route_ctx.peer_key.s); + if (peer) + pkg_free(cur_route_ctx.peer_key.s); } goto done;