Skip to content

Commit

Permalink
Usrloc: modify invalid contacts behaviour
Browse files Browse the repository at this point in the history
* stop inserting a contact even though received is OK
(call parse_uri() for each contact)
* at startup, if a bogus contact is found continue processing,
letting the user know that he has to remove that contact from
the database
  • Loading branch information
ionutrazvanionita committed Dec 21, 2015
1 parent a173499 commit ef76542
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions modules/usrloc/ucontact.c
Expand Up @@ -94,6 +94,8 @@ static int compute_next_hop(ucontact_t *contact)
*/
ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _ci)
{
struct sip_uri tmp_uri;

ucontact_t *c;

c = (ucontact_t*)shm_malloc(sizeof(ucontact_t));
Expand All @@ -103,6 +105,13 @@ ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _
}
memset(c, 0, sizeof(ucontact_t));

if (parse_uri(_contact->s, _contact->len, &tmp_uri) < 0) {
LM_ERR("contact [%.*s] is not valid! Will not store it!\n",
_contact->len, _contact->s);
shm_free(c);
return NULL;
}

if (shm_str_dup( &c->c, _contact) < 0) goto mem_error;
if (shm_str_dup( &c->callid, _ci->callid) < 0) goto mem_error;
if (shm_str_dup( &c->user_agent, _ci->user_agent) < 0) goto mem_error;
Expand Down
13 changes: 9 additions & 4 deletions modules/usrloc/udomain.c
Expand Up @@ -617,9 +617,16 @@ int preload_udomain(db_con_t* _c, udomain_t* _d)
}

if ( (c=mem_insert_ucontact(r, &contact, ci)) == 0) {
LM_ERR("inserting contact failed\n");
LM_ERR("inserting contact failed\n"
"Found a bad contact with "
"aor:[%.*s] contact:[%.*s] received:[%.*s]!\n"
"Will continue but that contact needs to be REMOVED!!\n",
r->aor.len, r->aor.s,
contact.len, contact.s,
ci->received.len, ci->received.s);
unlock_udomain(_d, &user);
goto error1;
free_ucontact(c);
continue;
}

/* We have to do this, because insert_ucontact sets state to CS_NEW
Expand All @@ -646,8 +653,6 @@ int preload_udomain(db_con_t* _c, udomain_t* _d)
#endif

return 0;
error1:
free_ucontact(c);
error:
ul_dbf.free_result(_c, res);
return -1;
Expand Down

0 comments on commit ef76542

Please sign in to comment.