diff options
author | George Joseph <george.joseph@fairview5.com> | 2015-04-27 11:11:40 -0600 |
---|---|---|
committer | George Joseph <george.joseph@fairview5.com> | 2015-04-27 11:11:40 -0600 |
commit | 99fb87ae13a1fc28bd5043600def3b373f85a0f6 (patch) | |
tree | f936206632f0ecfc59a065c39e43d0de7390cbf5 /res/res_pjsip/location.c | |
parent | e9788056e9f60a8ef6f810f0c5d31e0f3700e3bb (diff) |
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
Diffstat (limited to 'res/res_pjsip/location.c')
-rw-r--r-- | res/res_pjsip/location.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c index 45370dd24..887053b07 100644 --- a/res/res_pjsip/location.c +++ b/res/res_pjsip/location.c @@ -376,6 +376,11 @@ static int permanent_uri_handler(const struct aco_option *opt, struct ast_variab return -1; } + if (!ast_res_pjsip_find_or_create_contact_status(contact)) { + ao2_ref(contact, -1); + return -1; + } + ast_string_field_set(contact, uri, contact_uri); ao2_link(aor->permanent_contacts, contact); ao2_ref(contact, -1); @@ -750,8 +755,8 @@ static int cli_contact_print_body(void *obj, void *arg, int flags) "Contact", flexwidth, flexwidth, wrapper->contact_id, - ast_sip_get_contact_short_status_label(status->status), - (status->status != UNKNOWN ? ((long long) status->rtt) / 1000.0 : NAN)); + ast_sip_get_contact_short_status_label(status ? status->status : UNKNOWN), + (status && (status->status != UNKNOWN) ? ((long long) status->rtt) / 1000.0 : NAN)); return 0; } @@ -874,6 +879,17 @@ static struct ast_cli_entry cli_commands[] = { struct ast_sip_cli_formatter_entry *contact_formatter; struct ast_sip_cli_formatter_entry *aor_formatter; +/*! \brief Always create a contact_status for each contact */ +static int contact_apply_handler(const struct ast_sorcery *sorcery, void *object) +{ + struct ast_sip_contact_status *status; + struct ast_sip_contact *contact = object; + + status = ast_res_pjsip_find_or_create_contact_status(contact); + + return status ? 0 : -1; +} + /*! \brief Initialize sorcery with location support */ int ast_sip_initialize_sorcery_location(void) { @@ -881,7 +897,7 @@ int ast_sip_initialize_sorcery_location(void) ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar"); ast_sorcery_apply_default(sorcery, "aor", "config", "pjsip.conf,criteria=type=aor"); - if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, NULL) || + if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, contact_apply_handler) || ast_sorcery_object_register(sorcery, "aor", aor_alloc, NULL, NULL)) { return -1; } |