Blob Blame History Raw
From: rvlad-patrascu <vladp@opensips.org>
Date: Fri, 6 Oct 2017 19:47:12 +0300
Subject: [PATCH] acc: fix possbile memory leak when calling do_accounting() on
 CANCEL while "report_cancels" modparam not set

(cherry picked from commit aa32bf1b6909c8471eea8c2170a3a2a3f94be1cf)

Conflicts:
	modules/acc/acc_logic.c

diff --git a/modules/acc/acc_logic.c b/modules/acc/acc_logic.c
index 47daf4204..2072afb29 100644
--- a/modules/acc/acc_logic.c
+++ b/modules/acc/acc_logic.c
@@ -1086,6 +1086,17 @@ int w_do_acc_3(struct sip_msg* msg, char* type_p, char* flags_p, char* table_p)
 		return -1;
 	}
 
+	if (!msg) {
+		LM_ERR("no SIP message\n");
+		return -1;
+	}
+
+	if (skip_cancel(msg)) {
+		LM_WARN("do_accounting() called on CANCEL but 'report_cancels' modparam"
+				" not set - no accounting will be done for this transaction!\n");
+		return 1;
+	}
+
 	acc_param = (acc_type_param_t *)type_p;
 	if (acc_param->t == DO_ACC_PARAM_TYPE_VALUE) {
 		type = acc_param->u.ival;
@@ -1177,8 +1188,7 @@ int w_do_acc_3(struct sip_msg* msg, char* type_p, char* flags_p, char* table_p)
 	}
 
 
-	if ( msg && !skip_cancel(msg) &&
-	(is_acc_on(*flag_mask_p) || is_mc_acc_on(*flag_mask_p)) ) {
+	if (is_acc_on(*flag_mask_p) || is_mc_acc_on(*flag_mask_p)) {
 		/* do some parsing in advance */
 		if (acc_preparse_req(msg)<0)
 			return -1;