summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar BALATON Zoltan2014-10-22 23:01:05 +0200
committerGravatar Martin Szulecki2014-10-26 14:26:38 +0100
commitb3702104e85a8f8ec99e4e724f70516218e19ee9 (patch)
treec4821663e2f10c346545f1f8d53f60d2ae5f548a
parent8dc5f5ad7f04a2c2d1d31852f24f9e5bac4a9a53 (diff)
downloadlibimobiledevice-b3702104e85a8f8ec99e4e724f70516218e19ee9.tar.gz
libimobiledevice-b3702104e85a8f8ec99e4e724f70516218e19ee9.tar.bz2
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.
-rw-r--r--src/lockdown.c14
1 files 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;
}