res_pjsip: Fix SEGV on pending-qualify contacts

Permanent contacts that hadn't been qualified yet were missing
their contact_status entries causing SEGVs when running CLI
commands.

This patch makes sure that contact_statuses are created for
both dynamic and permanent contacts when they are created.
It also adds checks in the CLI code to make sure there's a
contact_status, just in case.

ASTERISK-25018 #close
Reported-by: Ivan Poddubny
Tested-by: Ivan Poddubny
Tested-by: George Joseph

Change-Id: I3cc13e5cedcafb24c400368b515b02d7fb81e029
This commit is contained in:
George Joseph
2015-04-27 11:11:40 -06:00
parent e9788056e9
commit 99fb87ae13
3 changed files with 31 additions and 9 deletions

View File

@@ -76,11 +76,10 @@ static void *contact_status_alloc(const char *name)
}
/*!
* \internal
* \brief Retrieve a ast_sip_contact_status object from sorcery creating
* one if not found.
*/
static struct ast_sip_contact_status *find_or_create_contact_status(const struct ast_sip_contact *contact)
struct ast_sip_contact_status *ast_res_pjsip_find_or_create_contact_status(const struct ast_sip_contact *contact)
{
struct ast_sip_contact_status *status;
@@ -98,6 +97,10 @@ static struct ast_sip_contact_status *find_or_create_contact_status(const struct
return NULL;
}
status->status = UNKNOWN;
status->rtt_start = ast_tv(0, 0);
status->rtt = 0;
if (ast_sorcery_create(ast_sip_get_sorcery(), status)) {
ast_log(LOG_ERROR, "Unable to persist ast_sip_contact_status for contact %s\n",
contact->uri);
@@ -118,7 +121,7 @@ static void update_contact_status(const struct ast_sip_contact *contact,
struct ast_sip_contact_status *status;
struct ast_sip_contact_status *update;
status = find_or_create_contact_status(contact);
status = ast_res_pjsip_find_or_create_contact_status(contact);
if (!status) {
ast_log(LOG_ERROR, "Unable to find ast_sip_contact_status for contact %s\n",
contact->uri);
@@ -143,8 +146,6 @@ static void update_contact_status(const struct ast_sip_contact *contact,
update->rtt_start = ast_tv(0, 0);
ast_test_suite_event_notify("AOR_CONTACT_QUALIFY_RESULT",
"Contact: %s\r\n"
"Status: %s\r\n"
@@ -172,7 +173,7 @@ static void init_start_time(const struct ast_sip_contact *contact)
struct ast_sip_contact_status *status;
struct ast_sip_contact_status *update;
status = find_or_create_contact_status(contact);
status = ast_res_pjsip_find_or_create_contact_status(contact);
if (!status) {
ast_log(LOG_ERROR, "Unable to find ast_sip_contact_status for contact %s\n",
contact->uri);