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
594 594
595 lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; 595 lockdownd_error_t ret = LOCKDOWN_E_SUCCESS;
596 lockdownd_client_t client_loc = NULL; 596 lockdownd_client_t client_loc = NULL;
597 plist_t pair_record = NULL;
597 char *host_id = NULL; 598 char *host_id = NULL;
598 char *type = NULL; 599 char *type = NULL;
599 600
@@ -612,10 +613,8 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi
612 debug_info("Warning QueryType request returned \"%s\".", type); 613 debug_info("Warning QueryType request returned \"%s\".", type);
613 } 614 }
614 } 615 }
615 if (type) 616 free(type);
616 free(type);
617 617
618 plist_t pair_record = NULL;
619 userpref_read_pair_record(client_loc->udid, &pair_record); 618 userpref_read_pair_record(client_loc->udid, &pair_record);
620 if (pair_record) { 619 if (pair_record) {
621 pair_record_get_host_id(pair_record, &host_id); 620 pair_record_get_host_id(pair_record, &host_id);
@@ -637,8 +636,9 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi
637 636
638 /* if not paired yet, let's do it now */ 637 /* if not paired yet, let's do it now */
639 if (LOCKDOWN_E_INVALID_HOST_ID == ret) { 638 if (LOCKDOWN_E_INVALID_HOST_ID == ret) {
639 free(host_id);
640 host_id = NULL;
640 ret = lockdownd_pair(client_loc, NULL); 641 ret = lockdownd_pair(client_loc, NULL);
641
642 if (LOCKDOWN_E_SUCCESS == ret) { 642 if (LOCKDOWN_E_SUCCESS == ret) {
643 ret = lockdownd_validate_pair(client_loc, NULL); 643 ret = lockdownd_validate_pair(client_loc, NULL);
644 } else if (LOCKDOWN_E_PAIRING_DIALOG_PENDING == ret) { 644 } else if (LOCKDOWN_E_PAIRING_DIALOG_PENDING == ret) {
@@ -660,10 +660,6 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi
660 debug_info("Session opening failed."); 660 debug_info("Session opening failed.");
661 } 661 }
662 662
663 if (host_id) {
664 free(host_id);
665 host_id = NULL;
666 }
667 } 663 }
668 664
669 if (LOCKDOWN_E_SUCCESS == ret) { 665 if (LOCKDOWN_E_SUCCESS == ret) {
@@ -671,7 +667,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi
671 } else { 667 } else {
672 lockdownd_client_free(client_loc); 668 lockdownd_client_free(client_loc);
673 } 669 }
674 670 free(host_id);
675 return ret; 671 return ret;
676} 672}
677 673