From: Sipwise Development Team <support@sipwise.com>
Date: Thu, 26 Mar 2020 10:06:46 +0100
Subject: presence_dfks_null_ptr_fixes

---
 src/modules/presence_dfks/add_events.c | 48 ++++++++++++++++------------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/modules/presence_dfks/add_events.c b/src/modules/presence_dfks/add_events.c
index cced370..24be2f4 100644
--- a/src/modules/presence_dfks/add_events.c
+++ b/src/modules/presence_dfks/add_events.c
@@ -156,14 +156,13 @@ int dfks_subs_handler(struct sip_msg* msg) {
 	if(top_elem != NULL) {
 		LM_DBG(" got SetDoNotDisturb\n");
 		param = libxml_api.xmlNodeGetNodeByName(top_elem, "doNotDisturbOn", NULL);
-		if(param!= NULL) {
+		if(param!= NULL)
 			dndact= (char*)xmlNodeGetContent(param);
-			if(dndact== NULL)  {
-				LM_ERR("while extracting value from 'doNotDisturbOn' in 'SetDoNotDisturb'\n");
-				goto error;
-			}
-			LM_DBG("got 'doNotDisturbOn'=%s in 'SetDoNotDisturb'\n",dndact);
+		if(dndact== NULL)  {
+			LM_ERR("while extracting value from 'doNotDisturbOn' in 'SetDoNotDisturb'\n");
+			goto error;
 		}
+		LM_DBG("got 'doNotDisturbOn'=%s in 'SetDoNotDisturb'\n",dndact);
 		param = NULL;
 		param = libxml_api.xmlNodeGetNodeByName(top_elem, "device", NULL);
 		if(param!= NULL) {
@@ -215,32 +214,29 @@ int dfks_subs_handler(struct sip_msg* msg) {
 	if(top_elem != NULL) {
 		LM_DBG(" got SetForwarding\n");
 		param = libxml_api.xmlNodeGetNodeByName(top_elem, "forwardDN", NULL);
-		if(param!= NULL) {
+		if(param!= NULL)
 			fwdDN= (char*)xmlNodeGetContent(param);
-			if(fwdDN== NULL) {
-				LM_ERR("while extracting value from 'forwardDN' in 'SetForwarding'\n");
-				goto error;
-			}
-			LM_DBG("got 'forwardDN'=%s in 'SetForwarding'\n",fwdDN);
+		if(fwdDN== NULL) {
+			LM_ERR("while extracting value from 'forwardDN' in 'SetForwarding'\n");
+			goto error;
 		}
+		LM_DBG("got 'forwardDN'=%s in 'SetForwarding'\n",fwdDN);
 		param = libxml_api.xmlNodeGetNodeByName(top_elem, "forwardingType", NULL);
-		if(param!= NULL) {
+		if(param!= NULL)
 			fwdtype= (char*)xmlNodeGetContent(param);
-			if(fwdtype== NULL) {
-				LM_ERR("while extracting value from 'forwardingType' in 'SetForwarding'\n");
-				goto error;
-			}
-			LM_DBG("got 'forwardingType'=%s in 'SetForwarding'\n",fwdtype);
+		if(fwdtype== NULL) {
+			LM_ERR("while extracting value from 'forwardingType' in 'SetForwarding'\n");
+			goto error;
 		}
+		LM_DBG("got 'forwardingType'=%s in 'SetForwarding'\n",fwdtype);
 		param = libxml_api.xmlNodeGetNodeByName(top_elem, "activateForward", NULL);
-		if(param!= NULL) {
+		if(param!= NULL)
 			fwdact= (char*)xmlNodeGetContent(param);
-			if(fwdact== NULL) {
-				LM_ERR("while extracting value from 'activateForward' in 'SetForwarding'\n");
-				goto error;
-			}
-			LM_DBG("got 'activateForward'=%s in 'SetForwarding'\n",fwdact);
+		if(fwdact== NULL) {
+			LM_ERR("while extracting value from 'activateForward' in 'SetForwarding'\n");
+			goto error;
 		}
+		LM_DBG("got 'activateForward'=%s in 'SetForwarding'\n",fwdact);
 		param = libxml_api.xmlNodeGetNodeByName(top_elem, "device", NULL);
 		if(param!= NULL) {
 			device= (char*)xmlNodeGetContent(param);
@@ -250,7 +246,9 @@ int dfks_subs_handler(struct sip_msg* msg) {
 			}
 			LM_DBG("got 'device'=%s in 'SetDoNotDisturb'\n",device);
 		}
-		body.len=fwd_xml.len -8 + strlen(device) + strlen(device) +strlen(fwdtype) + strlen(fwdact) +strlen(fwdDN);
+		else
+			device=unk_dev.s;
+		body.len=fwd_xml.len -8 + strlen(device) +strlen(fwdtype) + strlen(fwdact) +strlen(fwdDN);
 		body.s=pkg_malloc(body.len+1);
 		if(body.s== NULL)  {
 			LM_ERR("while extracting allocating body for publish in 'SetForwarding'\n");
