Skip to content

Commit

Permalink
Fix global msg context leakage in error_route
Browse files Browse the repository at this point in the history
While commit b5bcf04 fixed an issue with missing contexts during
error_route, it was missed that the "parse_error" label does *not* free
up the global context.

The effects of this bug were mostly hidden, affecting only opensips.cfg
scripts which employ the "error_route", causing a slow PKG memory leak,
proportional to the amount of bad SIP received.  Moreover, if these
scripts also use async(), they may occassionally run into a quick
abort() in t_resume_async(), due to a context being already set (BUG).

(cherry picked from commit 43ee34b)
  • Loading branch information
liviuchircu committed Oct 12, 2022
1 parent d6be026 commit c0d189c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ unsigned int get_next_msg_no(void)
int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info,
context_p existing_context, unsigned int msg_flags)
{
#define reset_global_context() \
do {\
if (!current_processing_ctx) { \
ctx = NULL; \
} else { \
context_destroy(CONTEXT_GLOBAL, ctx); \
current_processing_ctx = NULL; \
} \
} while (0)
static context_p ctx = NULL;

struct sip_msg* msg;
struct timeval start;
int rc, old_route_type;
Expand Down Expand Up @@ -153,6 +163,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info,
prepare_context( ctx, parse_error );
current_processing_ctx = ctx;
run_error_route(msg, 1);
reset_global_context();
}
goto parse_error;
}
Expand Down Expand Up @@ -274,15 +285,8 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info,
}

end:
reset_global_context();

/* if someone else set the context, then we should also "release" the
* static ctx. */
if (current_processing_ctx == NULL)
ctx = NULL;
else
context_destroy(CONTEXT_GLOBAL, ctx);

current_processing_ctx = NULL;
__stop_expire_timer( start, execmsgthreshold, "msg processing",
msg->buf, msg->len, 0, slow_msgs);
reset_longest_action_list(execmsgthreshold);
Expand Down

0 comments on commit c0d189c

Please sign in to comment.