Browse code

dialog: dlg_get_var assure return null on error

Victor Seva authored on 27/05/2022 14:58:28
Showing 1 changed files
... ...
@@ -1570,53 +1570,62 @@ static int w_dlg_get_var(struct sip_msg *msg, char *ci, char *ft, char *tt, char
1570 1570
 	str k = STR_NULL;
1571 1571
 	str *val = NULL;
1572 1572
 	pv_value_t dst_val;
1573
-	pv_spec_t* dst_pv;
1573
+	pv_spec_t* dst_pv = (pv_spec_t *)pv;
1574 1574
 
1575 1575
 	if(ci==0 || ft==0 || tt==0)
1576 1576
 	{
1577 1577
 		LM_ERR("invalid parameters\n");
1578
-		return -1;
1578
+		goto error;
1579 1579
 	}
1580 1580
 
1581 1581
 	if(fixup_get_svalue(msg, (gparam_p)ci, &sc)!=0)
1582 1582
 	{
1583 1583
 		LM_ERR("unable to get Call-ID\n");
1584
-		return -1;
1584
+		goto error;
1585 1585
 	}
1586 1586
 
1587 1587
 	if(fixup_get_svalue(msg, (gparam_p)ft, &sf)!=0)
1588 1588
 	{
1589 1589
 		LM_ERR("unable to get From tag\n");
1590
-		return -1;
1590
+		goto error;
1591 1591
 	}
1592 1592
 
1593 1593
 	if(fixup_get_svalue(msg, (gparam_p)tt, &st)!=0)
1594 1594
 	{
1595 1595
 		LM_ERR("unable to get To Tag\n");
1596
-		return -1;
1596
+		goto error;
1597 1597
 	}
1598 1598
 	if(st.s==NULL || st.len == 0)
1599 1599
 	{
1600 1600
 		LM_ERR("invalid To tag parameter\n");
1601
-		return -1;
1601
+		goto error;
1602 1602
 	}
1603 1603
 	if(fixup_get_svalue(msg, (gparam_p)key, &k)!=0)
1604 1604
 	{
1605 1605
 		LM_ERR("unable to get key name\n");
1606
-		return -1;
1606
+		goto error;
1607 1607
 	}
1608
-	dst_pv = (pv_spec_t *)pv;
1609
-	val = ki_dlg_get_var_helper(msg, &sc, &sf, &st, &k);
1608
+	val = ki_dlg_get_var(msg, &sc, &sf, &st, &k);
1610 1609
 	if(val) {
1611 1610
 		memset(&dst_val, 0, sizeof(pv_value_t));
1612 1611
 		dst_val.flags |= PV_VAL_STR;
1613 1612
 		dst_val.rs.s = val->s;
1614 1613
 		dst_val.rs.len = val->len;
1615
-		if(pv_set_spec_value(msg, dst_pv, 0, &dst_val) != 0) return -1;
1616 1614
 	} else {
1617
-		if(pv_get_null(msg, NULL, &dst_val) != 0) return -1;
1615
+		pv_get_null(msg, NULL, &dst_val);
1616
+	}
1617
+	if(pv_set_spec_value(msg, dst_pv, 0, &dst_val) != 0) {
1618
+		LM_ERR("unable to set value to dst_pv\n");
1619
+		if(val) goto error; else return -1;
1618 1620
 	}
1619 1621
 	return 1;
1622
+
1623
+error:
1624
+	pv_get_null(msg, NULL, &dst_val);
1625
+	if(pv_set_spec_value(msg, dst_pv, 0, &dst_val) != 0) {
1626
+		LM_ERR("unable to set null value to dst_pv\n");
1627
+	}
1628
+	return -1;
1620 1629
 }
1621 1630
 
1622 1631
 static int fixup_dlg_get_var(void** param, int param_no)