From b5af70a2b464cae1058ec53bb8dbea5ca07e6d4e Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 10 Jul 2017 11:27:47 +0200 Subject: [PATCH] tm: several checks for return codes for better error handling --- src/modules/tm/t_fifo.c | 7 ++++++- src/modules/tm/t_fwd.c | 5 ++++- src/modules/tm/t_msgbuilder.c | 8 ++++++-- src/modules/tm/t_reply.c | 4 +++- src/modules/tm/t_serial.c | 6 ++++-- src/modules/tm/tm.c | 2 +- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/modules/tm/t_fifo.c b/src/modules/tm/t_fifo.c index 2a983d354fb..2565232209e 100644 --- a/src/modules/tm/t_fifo.c +++ b/src/modules/tm/t_fifo.c @@ -167,7 +167,7 @@ int parse_tw_append( modparam_t type, void* val) { struct hdr_field hdr; struct hdr_avp *last; - struct hdr_avp *ha; + struct hdr_avp *ha=NULL; struct tw_append *app; int_str avp_name; char *s; @@ -376,6 +376,7 @@ int parse_tw_append( modparam_t type, void* val) last->next = ha; last = ha; } + ha = NULL; } } /* end while */ @@ -388,6 +389,7 @@ int parse_tw_append( modparam_t type, void* val) LM_ERR("parse error in <%s> around position %ld\n", (char*)val, (long)(s-(char*)val)); error: + if(ha) pkg_free(ha); return -1; } @@ -421,16 +423,19 @@ int fixup_t_write( void** param, int param_no) twi->action.len = s - twi->action.s; if (twi->action.len==0) { LM_ERR("empty action name\n"); + pkg_free(twi); return E_CFG; } s++; if (*s==0) { LM_ERR("empty append name\n"); + pkg_free(twi); return E_CFG; } twi->append = search_tw_append( s, strlen(s)); if (twi->append==0) { LM_ERR("unknown append name <%s>\n",s); + pkg_free(twi); return E_CFG; } } else { diff --git a/src/modules/tm/t_fwd.c b/src/modules/tm/t_fwd.c index 5cc649ebdde..64d1036ffca 100644 --- a/src/modules/tm/t_fwd.c +++ b/src/modules/tm/t_fwd.c @@ -1168,7 +1168,10 @@ static struct cancel_reason* cancel_reason_pack(short cause, void* data, data && !(t->flags & T_NO_E2E_CANCEL_REASON))) { /* parse the entire cancel, to get all the Reason headers */ e2e_cancel = data; - parse_headers(e2e_cancel, HDR_EOH_F, 0); + if(parse_headers(e2e_cancel, HDR_EOH_F, 0)==-1) { + LM_ERR("failed to parse headers\n"); + goto error; + } for(hdr=get_hdr(e2e_cancel, HDR_REASON_T), reas1=hdr; hdr; hdr=next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ diff --git a/src/modules/tm/t_msgbuilder.c b/src/modules/tm/t_msgbuilder.c index 5a20dcf8a69..f1f107b53ea 100644 --- a/src/modules/tm/t_msgbuilder.c +++ b/src/modules/tm/t_msgbuilder.c @@ -159,7 +159,9 @@ char *build_local(struct cell *Trans,unsigned int branch, reason->u.e2e_cancel && !(Trans->flags & T_NO_E2E_CANCEL_REASON)) { /* parse the entire cancel, to get all the Reason headers */ - parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0); + if(parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0)<0) { + LM_WARN("failed to parse headers\n"); + } for(hdr=get_hdr(reason->u.e2e_cancel, HDR_REASON_T), reas1=hdr; hdr; hdr=next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ @@ -313,7 +315,9 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch, reason->u.e2e_cancel && !(Trans->flags & T_NO_E2E_CANCEL_REASON)) { /* parse the entire cancel, to get all the Reason headers */ - parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0); + if(parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0)<0) { + LM_WARN("failed to parse headers\n"); + } for(hdr=get_hdr(reason->u.e2e_cancel, HDR_REASON_T), reas1=hdr; hdr; hdr=next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ diff --git a/src/modules/tm/t_reply.c b/src/modules/tm/t_reply.c index cc39c867a94..cb8dc60e06f 100644 --- a/src/modules/tm/t_reply.c +++ b/src/modules/tm/t_reply.c @@ -1579,7 +1579,9 @@ int t_retransmit_reply( struct cell *t ) } memcpy( b, t->uas.response.buffer, len ); UNLOCK_REPLIES( t ); - SEND_PR_BUFFER( & t->uas.response, b, len ); + if(SEND_PR_BUFFER( & t->uas.response, b, len )<0) { + LM_WARN("send pr buffer failed\n"); + } if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){ /* we don't know if it's a retransmission of a local reply or a * forwarded reply */ diff --git a/src/modules/tm/t_serial.c b/src/modules/tm/t_serial.c index 2fcb247fa88..019b35dbb42 100644 --- a/src/modules/tm/t_serial.c +++ b/src/modules/tm/t_serial.c @@ -558,7 +558,9 @@ int ki_t_next_contacts(struct sip_msg* msg) } if (dst_uri.len) { - set_dst_uri(msg, &dst_uri); + if(set_dst_uri(msg, &dst_uri)<0) { + LM_ERR("failed to set dst uri\n"); + } } else { reset_dst_uri(msg); } @@ -880,4 +882,4 @@ int ki_t_next_contact_flow(struct sip_msg* msg) int t_next_contact_flow(struct sip_msg* msg, char* key, char* value) { return ki_t_next_contact_flow(msg); -} \ No newline at end of file +} diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c index e6fbde7eb86..0be38c7979d 100644 --- a/src/modules/tm/tm.c +++ b/src/modules/tm/tm.c @@ -1026,7 +1026,7 @@ inline static int w_t_lookup_cancel(struct sip_msg* msg, char* str, char* str2) int i = 0; if(str) { - get_int_fparam(&i, msg, (fparam_t*)str); + if(get_int_fparam(&i, msg, (fparam_t*)str)<0) return -1; } return ki_t_lookup_cancel_flags(msg, i); }