Skip to content

Commit

Permalink
b2b_logic: prevent initializing B2B session on non-INVITEs
Browse files Browse the repository at this point in the history
This prevents crashes when the b2b_init_request() function is used on
methods other than INVITE or from other routes than request routes where
the INVITE SIP message is visible.

Related to #3102

(cherry picked from commit 8c0a9e0)
  • Loading branch information
rvlad-patrascu committed Jun 16, 2023
1 parent 37f2498 commit c8182aa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/b2b_logic/logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -3358,6 +3358,13 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf,
struct sip_uri ct_uri;
int maxfwd;

if (!str_match((_str("INVITE")), &msg->first_line.u.request.method)) {
LM_ERR("Scenario must be initialized on INVITE but got method: %.*s\n",
msg->first_line.u.request.method.len,
msg->first_line.u.request.method.s);
return NULL;
}

if(b2b_msg_get_from(msg, &from_uri, &from_dname)< 0 || b2b_msg_get_to(msg, &to_uri, params->flags)< 0)
{
LM_ERR("Failed to get to or from from the message\n");
Expand Down Expand Up @@ -3700,6 +3707,13 @@ str* b2b_process_scenario_init(struct sip_msg* msg, b2bl_cback_f cbf,
goto error;
}

if (!str_match(&method, &msg->first_line.u.request.method)) {
LM_ERR("Scenario must be initialized on INVITE but got method: %.*s\n",
msg->first_line.u.request.method.len,
msg->first_line.u.request.method.s);
goto error;
}

if(b2b_msg_get_from(msg, &from_uri, &from_dname)< 0 ||
b2b_msg_get_to(msg, &to_uri, init_params->flags)< 0)
{
Expand Down

0 comments on commit c8182aa

Please sign in to comment.