[sr-dev] git:master:ed861cfe: presence: safety check for structure vars before accessing fields

Daniel-Constantin Mierla miconda at gmail.com
Mon Nov 19 10:18:17 CET 2018


Module: kamailio
Branch: master
Commit: ed861cfe7f0f4e265b6dc104a79d07ad7d2997e2
URL: https://github.com/kamailio/kamailio/commit/ed861cfe7f0f4e265b6dc104a79d07ad7d2997e2

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-11-19T10:17:27+01:00

presence: safety check for structure vars before accessing fields

---

Modified: src/modules/presence/presence_dmq.c
Modified: src/modules/presence/presentity.c

---

Diff:  https://github.com/kamailio/kamailio/commit/ed861cfe7f0f4e265b6dc104a79d07ad7d2997e2.diff
Patch: https://github.com/kamailio/kamailio/commit/ed861cfe7f0f4e265b6dc104a79d07ad7d2997e2.patch

---

diff --git a/src/modules/presence/presence_dmq.c b/src/modules/presence/presence_dmq.c
index 9ce259eeaa..258116d53a 100644
--- a/src/modules/presence/presence_dmq.c
+++ b/src/modules/presence/presence_dmq.c
@@ -193,9 +193,13 @@ presentity_t *pres_parse_json_presentity(srjson_t *in)
 		}
 	}
 
+	if(!p_event) {
+		LM_ERR("presence event not found\n");
+		return NULL;
+	}
+
 	LM_DBG("building presentity from domain: %.*s, user: %.*s, expires: %d, "
-		   "event: "
-		   "%.*s, etag: %.*s, sender: %.*s",
+		   "event: %.*s, etag: %.*s, sender: %.*s",
 			p_domain.len, p_domain.s, p_user.len, p_user.s, p_expires,
 			p_event->name.len, p_event->name.s, p_etag.len, p_etag.s,
 			p_sender.len, p_sender.s);
@@ -301,9 +305,9 @@ int pres_dmq_handle_msg(
 
 	switch(action) {
 		case PRES_DMQ_UPDATE_PRESENTITY:
-			if(update_presentity(NULL, presentity, &p_body, t_new, &sent_reply,
-					   sphere, &cur_etag, &ruid, 0)
-					< 0) {
+			if(presentity==NULL
+					|| update_presentity(NULL, presentity, &p_body, t_new,
+							&sent_reply, sphere, &cur_etag, &ruid, 0) < 0) {
 				goto error;
 			}
 			break;
diff --git a/src/modules/presence/presentity.c b/src/modules/presence/presentity.c
index 497bfa95ea..5527d3736a 100644
--- a/src/modules/presence/presentity.c
+++ b/src/modules/presence/presentity.c
@@ -807,7 +807,6 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
 	}
 	else
 	{
-
 		LM_DBG("updating existing presentity with etag %.*s\n", presentity->etag.len, presentity->etag.s);
 
 		if (ruid) {
@@ -1265,7 +1264,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
 
 done:
 
-	if (pres_enable_dmq>0) {
+	if (pres_enable_dmq>0 && p_ruid.s!=NULL) {
 		pres_dmq_replicate_presentity(presentity, body, new_t, &cur_etag, sphere, &p_ruid, NULL);
 	}
 
@@ -1934,9 +1933,9 @@ int delete_offline_presentities(str *pres_uri, pres_ev_t *event)
 int _api_update_presentity(str *event, str *realm, str *user, str *etag,
 		str *sender, str *body, int expires, int new_t, int replace)
 {
-	int ret;
+	int ret = -1;
 	presentity_t *pres = NULL;
-	pres_ev_t *ev;
+	pres_ev_t *ev = NULL;
 	char *sphere = NULL;
 
 	ev = contains_event(event, NULL);
@@ -1950,10 +1949,12 @@ int _api_update_presentity(str *event, str *realm, str *user, str *etag,
 	if(sphere_enable) {
 		sphere = extract_sphere(*body);
 	}
-	ret = update_presentity(NULL, pres, body, new_t, NULL, sphere, NULL, NULL, replace);
-
-	if(pres)
+	if(pres) {
+		ret = update_presentity(NULL, pres, body, new_t, NULL, sphere, NULL,
+					NULL, replace);
 		pkg_free(pres);
+	}
+
 	if(sphere)
 		pkg_free(sphere);
 




More information about the sr-dev mailing list