From af1ff6a113d94aeaff017b8b7622bbca06f67c2c Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 28 Oct 2015 09:33:53 +0100 Subject: [PATCH] liblinphone: fix potential crash when interpretting URLs --- Classes/ChatConversationCreateTableView.m | 12 ++++++++---- Classes/ContactDetailsView.m | 8 +++++--- Classes/LinphoneUI/UIContactDetailsCell.m | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index a2adecf8f..d828b8860 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -40,10 +40,14 @@ } } // also add current entry, if not listed - const LinphoneAddress *addr = linphone_core_interpret_url([LinphoneManager getLc], filter.UTF8String); - char *uri = linphone_address_as_string(addr); - NSString *nsuri = [NSString stringWithUTF8String:uri]; - ms_free(uri); + LinphoneAddress *addr = linphone_core_interpret_url([LinphoneManager getLc], filter.UTF8String); + NSString *nsuri = filter; + if (addr) { + char *uri = linphone_address_as_string(addr); + nsuri = [NSString stringWithUTF8String:uri]; + ms_free(uri); + linphone_address_destroy(addr); + } if (![_contacts containsObject:nsuri]) { [_contacts insertObject:nsuri atIndex:0]; } diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 7ffe86daf..fdd7dfc8e 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -126,7 +126,8 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info - (void)addCurrentContactContactField:(NSString *)address { LinphoneAddress *linphoneAddress = linphone_core_interpret_url([LinphoneManager getLc], address.UTF8String); - NSString *username = [NSString stringWithUTF8String:linphone_address_get_username(linphoneAddress)]; + NSString *username = + linphoneAddress ? [NSString stringWithUTF8String:linphone_address_get_username(linphoneAddress)] : address; if (([username rangeOfString:@"@"].length > 0) && ([[LinphoneManager instance] lpConfigBoolForKey:@"show_contacts_emails_preference"] == true)) { @@ -137,8 +138,9 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info } else { [_tableController addSipField:address]; } - linphone_address_destroy(linphoneAddress); - + if (linphoneAddress) { + linphone_address_destroy(linphoneAddress); + } [self setEditing:FALSE]; [[_tableController tableView] reloadData]; } diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index eb37e12fe..967450d35 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -61,9 +61,9 @@ - (IBAction)onCallClick:(id)event { LinphoneAddress *addr = linphone_core_interpret_url([LinphoneManager getLc], _addressLabel.text.UTF8String); - char *lAddress = linphone_address_as_string_uri_only(addr); - if (lAddress == NULL) + if (addr == NULL) return; + char *lAddress = linphone_address_as_string_uri_only(addr); NSString *displayName = [FastAddressBook displayNameForAddress:addr]; DialerView *view = VIEW(DialerView);