Browse Source

presence: safety check for structure vars before accessing fields

Daniel-Constantin Mierla 6 years ago
parent
commit
ed861cfe7f
2 changed files with 17 additions and 12 deletions
  1. 9 5
      src/modules/presence/presence_dmq.c
  2. 8 7
      src/modules/presence/presentity.c

+ 9 - 5
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;

+ 8 - 7
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 @@ send_notify:
 
 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 @@ error:
 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);