Преглед изворни кода

pv: initialize sbranch via function and check return value

- reported by Anthony Messina, GH#141
Daniel-Constantin Mierla пре 10 година
родитељ
комит
1bb85845de
3 измењених фајлова са 15 додато и 8 уклоњено
  1. 5 4
      modules/pv/pv.c
  2. 9 4
      modules/pv/pv_branch.c
  3. 1 0
      modules/pv/pv_branch.h

+ 5 - 4
modules/pv/pv.c

@@ -541,10 +541,11 @@ static int mod_init(void)
 		return -1;
 	}
 	if(pv_init_rpc()!=0)
-        {
-                LM_ERR("failed to register RPC commands\n");
-                return -1;
-        }
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+    }
+	pv_init_sbranch();
 
 	return 0;
 }

+ 9 - 4
modules/pv/pv_branch.c

@@ -27,7 +27,12 @@
 #include "pv_core.h"
 #include "pv_branch.h"
 
-static branch_t _pv_sbranch = {0};
+static branch_t _pv_sbranch;
+
+void pv_init_sbranch(void)
+{
+	memset(&_pv_sbranch, 0, sizeof(branch_t));
+}
 
 int pv_get_branchx_helper(sip_msg_t *msg, pv_param_t *param,
 		pv_value_t *res, int btype)
@@ -46,6 +51,9 @@ int pv_get_branchx_helper(sip_msg_t *msg, pv_param_t *param,
 			return pv_get_null(msg, param, res);
 		}
 		br = get_sip_branch(idx);
+		if(br==NULL) {
+			return pv_get_null(msg, param, res);
+		}
 	}
 
 	/* branch(count) doesn't need a valid branch, everything else does */
@@ -685,10 +693,7 @@ int sbranch_append(sip_msg_t *msg)
 {
 	str uri = {0};
 	str duri = {0};
-	int lq = 0;
 	str path = {0};
-	unsigned int fl = 0;
-	struct socket_info* fsocket = NULL;
 	str ruid = {0};
 	str location_ua = {0};
 	branch_t *br;

+ 1 - 0
modules/pv/pv_branch.h

@@ -46,6 +46,7 @@ int pv_parse_nh_name(pv_spec_p sp, str *in);
 
 int sbranch_set_ruri(sip_msg_t *msg);
 int sbranch_append(sip_msg_t *msg);
+void pv_init_sbranch(void);
 int sbranch_reset(void);
 
 #endif