Jelajahi Sumber

tm: several checks for return codes for better error handling

Daniel-Constantin Mierla 8 tahun lalu
induk
melakukan
b5af70a2b4

+ 6 - 1
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 @@ parse_error:
 	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 {

+ 4 - 1
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 */

+ 6 - 2
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 */

+ 3 - 1
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 */

+ 4 - 2
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 @@ next_xavp:
 int t_next_contact_flow(struct sip_msg* msg, char* key, char* value)
 {
 	return ki_t_next_contact_flow(msg);
-}
+}

+ 1 - 1
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);
 }