Skip to content

Commit

Permalink
presence: safety check for structure vars before accessing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Nov 19, 2018
1 parent 95d56e9 commit ed861cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 9 additions & 5 deletions src/modules/presence/presence_dmq.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions src/modules/presence/presentity.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down

0 comments on commit ed861cf

Please sign in to comment.