Skip to content

Commit 1ad77d2

Browse files
committed
Fix 0'ed msg passed to callbacks on parse error.
This is a complition to af754d9 In receive_msg(), even upon a parse error, we need the cripled msg to be passed to "error" handling callbacks (like pike or error_route).
1 parent 285774d commit 1ad77d2

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

parser/msg_parser.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ int clone_headers(struct sip_msg *from_msg, struct sip_msg *to_msg)
818818

819819

820820
/* returns 0 if ok, -1 for errors */
821-
int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
821+
int parse_msg_opt(char* buf, unsigned int len, struct sip_msg* msg,
822+
int free_on_err)
822823
{
823824

824825
char *tmp;
@@ -925,9 +926,12 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
925926
return 0;
926927

927928
parse_error:
928-
/* Free the SIP message if it has already been created to prevent memory leaks */
929-
free_sip_msg(msg);
930-
memset(msg, 0, sizeof(*msg));
929+
if (free_on_err) {
930+
/* Free the SIP message if it has already been created to
931+
* prevent memory leaks */
932+
free_sip_msg(msg);
933+
memset(msg, 0, sizeof(*msg));
934+
}
931935

932936
error:
933937
/* more debugging, msg->orig is/should be null terminated*/

parser/msg_parser.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ struct sip_msg {
363363

364364
extern int via_cnt;
365365

366-
int parse_msg(char* buf, unsigned int len, struct sip_msg* msg);
366+
#define parse_msg( _buf, _len, _msg) \
367+
parse_msg_opt( _buf, _len, _msg, 1)
368+
369+
int parse_msg_opt(char* buf, unsigned int len, struct sip_msg* msg,
370+
int free_on_err);
367371

368372
#define parse_headers(msg, flags,next) parse_headers_aux(msg,flags,next, 1)
369373

receive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info,
152152
msg->msg_flags=msg_flags;
153153
msg->ruri_q = Q_UNSPECIFIED;
154154

155-
if (parse_msg(in_buff.s,len, msg)!=0){
155+
if (parse_msg_opt(in_buff.s,len, msg, 0)!=0){
156156
tmp=ip_addr2a(&(rcv_info->src_ip));
157157
LM_ERR("Unable to parse msg received from [%s:%d]\n",
158158
tmp, rcv_info->src_port);

0 commit comments

Comments
 (0)