From b3702104e85a8f8ec99e4e724f70516218e19ee9 Mon Sep 17 00:00:00 2001 From: BALATON Zoltan Date: Wed, 22 Oct 2014 23:01:05 +0200 Subject: lockdown: Fix error in re-pairing when previous record became invalid When connecting with an existing pair record failed we attempted to pair again which generated a new host id but then connect after successful pairing tried to use host id from the old record and failed. Make sure we forget the old host id when re-pairing. This also fixes a possible memory leak. --- src/lockdown.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/lockdown.c b/src/lockdown.c index 14886c9..20c3cb6 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -594,6 +594,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; lockdownd_client_t client_loc = NULL; + plist_t pair_record = NULL; char *host_id = NULL; char *type = NULL; @@ -612,10 +613,8 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi debug_info("Warning QueryType request returned \"%s\".", type); } } - if (type) - free(type); + free(type); - plist_t pair_record = NULL; userpref_read_pair_record(client_loc->udid, &pair_record); if (pair_record) { pair_record_get_host_id(pair_record, &host_id); @@ -637,8 +636,9 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi /* if not paired yet, let's do it now */ if (LOCKDOWN_E_INVALID_HOST_ID == ret) { + free(host_id); + host_id = NULL; ret = lockdownd_pair(client_loc, NULL); - if (LOCKDOWN_E_SUCCESS == ret) { ret = lockdownd_validate_pair(client_loc, NULL); } else if (LOCKDOWN_E_PAIRING_DIALOG_PENDING == ret) { @@ -660,10 +660,6 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi debug_info("Session opening failed."); } - if (host_id) { - free(host_id); - host_id = NULL; - } } if (LOCKDOWN_E_SUCCESS == ret) { @@ -671,7 +667,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi } else { lockdownd_client_free(client_loc); } - + free(host_id); return ret; } -- cgit v1.1-32-gdbae