Skip to content

Commit

Permalink
Merge pull request #3038 from okhowang/tracer-leak
Browse files Browse the repository at this point in the history
tracer: Don't modify shm msg in trace_onreply_out
(cherry picked from commit 9c2d99d)
  • Loading branch information
bogdan-iancu committed Mar 23, 2023
1 parent c312b5a commit 1e9c492
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions modules/tracer/tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2336,54 +2336,60 @@ static void trace_slack_in(struct sip_msg* req, str *buffer,int rpl_code,
}
#endif

static void trace_msg_out(struct sip_msg* msg, str *sbuf,
struct socket_info* send_sock, int proto, union sockaddr_union *to,
trace_info_p info, int leg_flag)
{
static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12];
static char toip_buff[IP_ADDR_MAX_STR_SIZE+12];
struct ip_addr to_ip;
trace_instance_p instance;
static int parse_from_and_callid(struct sip_msg* msg, str *from_tag) {
struct to_body from_b;
str from_tag;

if (msg->msg_flags&FL_SHM_CLONE) {
/* this is an in shm-mem cloned msg,
* so do not do direct parsing on it ; keep in mind that the hdrs are
* already parsed/found, so we may need to parse here only
* their body/payload */
if (msg->from) {
if (get_from(msg)) {
from_tag = get_from(msg)->tag_value;
*from_tag = get_from(msg)->tag_value;
} else {
parse_to( msg->from->body.s,
msg->from->body.s+msg->from->body.len+1, &from_b);
if (from_b.error == PARSE_ERROR) {
from_tag.s = NULL;
from_tag.s = 0;
return -1;
} else {
from_tag = from_b.tag_value;
*from_tag = from_b.tag_value;
free_to_params(&from_b);
}
}
} else {
from_tag.s = NULL;
from_tag.s = 0;
return -2;
}
} else {
if(parse_from_header(msg)==-1||msg->from==NULL||get_from(msg)==NULL)
{
LM_ERR("cannot parse FROM header\n");
goto error;
return -3;
}
from_tag = get_from(msg)->tag_value;
*from_tag = get_from(msg)->tag_value;

if(parse_headers(msg, HDR_CALLID_F, 0)!=0)
{
LM_ERR("cannot parse call-id\n");
return;
return -4;
}
}
return 0;
}

static void trace_msg_out(struct sip_msg* msg, str *sbuf,
struct socket_info* send_sock, int proto, union sockaddr_union *to,
trace_info_p info, int leg_flag)
{
static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12];
static char toip_buff[IP_ADDR_MAX_STR_SIZE+12];
struct ip_addr to_ip;
trace_instance_p instance;
str from_tag;

if(parse_from_and_callid(msg, &from_tag) != 0)
{
goto error;
}

LM_DBG("trace msg out \n");

Expand Down Expand Up @@ -2626,6 +2632,7 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps,
char statusbuf[8];
str *sbuf;
struct dest_info *dst;
str from_tag;

trace_info_t info;

Expand All @@ -2645,18 +2652,11 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps,
faked = 1;
}

if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL)
if(parse_from_and_callid(msg, &from_tag) != 0)
{
LM_ERR("cannot parse FROM header\n");
goto error;
}

if(parse_headers(msg, HDR_CALLID_F, 0)!=0)
{
LM_ERR("cannot parse call-id\n");
return;
}

if(msg->callid==NULL || msg->callid->body.s==NULL)
{
LM_ERR("cannot find Call-ID header!\n");
Expand Down Expand Up @@ -2751,8 +2751,7 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps,

db_vals[11].val.string_val = "out";

db_vals[12].val.str_val.s = get_from(msg)->tag_value.s;
db_vals[12].val.str_val.len = get_from(msg)->tag_value.len;
db_vals[12].val.str_val = from_tag;

for (instance = info.instances; instance; instance = instance->next) {
if ( trace_check_legs( instance, leg_flag)) {
Expand Down

0 comments on commit 1e9c492

Please sign in to comment.