summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-03-14 03:09:14 +0100
committerGravatar Nikias Bassen2013-03-14 03:09:14 +0100
commit4222bc1b880d6535462e3b5ba5431809a3c5fddc (patch)
treeb664bbdfe96d162930b2719ec920cd149684b0ed
parent23abc8303b8cad9251cd4ea4b5fa5af28e5f0b24 (diff)
downloadlibimobiledevice-4222bc1b880d6535462e3b5ba5431809a3c5fddc.tar.gz
libimobiledevice-4222bc1b880d6535462e3b5ba5431809a3c5fddc.tar.bz2
global: make sure to check service before checking service->port to prevent crashes
-rw-r--r--dev/afccheck.c2
-rw-r--r--dev/ideviceclient.c17
-rw-r--r--src/afc.c2
-rw-r--r--src/device_link_service.c2
-rw-r--r--src/diagnostics_relay.c2
-rw-r--r--src/file_relay.c2
-rw-r--r--src/heartbeat.c6
-rw-r--r--src/house_arrest.c3
-rw-r--r--src/installation_proxy.c8
-rw-r--r--src/misagent.c3
-rw-r--r--src/mobile_image_mounter.c8
-rw-r--r--src/mobilebackup.c5
-rw-r--r--src/mobilebackup2.c2
-rw-r--r--src/mobilesync.c2
-rw-r--r--src/notification_proxy.c8
-rw-r--r--src/property_list_service.c2
-rw-r--r--src/sbservices.c3
-rw-r--r--src/screenshotr.c2
-rw-r--r--src/service.c4
-rw-r--r--src/webinspector.c6
-rw-r--r--tools/idevicebackup.c11
-rw-r--r--tools/idevicebackup2.c11
-rw-r--r--tools/idevicedebugserverproxy.c2
-rw-r--r--tools/idevicediagnostics.c2
-rw-r--r--tools/ideviceimagemounter.c4
-rw-r--r--tools/idevicescreenshot.c2
26 files changed, 44 insertions, 77 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c
index ead0ca0..d7ee7d1 100644
--- a/dev/afccheck.c
+++ b/dev/afccheck.c
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
111 return 1; 111 return 1;
112 } 112 }
113 113
114 if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &service) && !service->port) { 114 if (LOCKDOWN_E_SUCCESS != lockdownd_start_service(client, "com.apple.afc", &service) || !service || !service->port) {
115 lockdownd_client_free(client); 115 lockdownd_client_free(client);
116 idevice_free(phone); 116 idevice_free(phone);
117 fprintf(stderr, "Something went wrong when starting AFC."); 117 fprintf(stderr, "Something went wrong when starting AFC.");
diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c
index c8635d8..778f20e 100644
--- a/dev/ideviceclient.c
+++ b/dev/ideviceclient.c
@@ -49,7 +49,7 @@ static void perform_notification(idevice_t phone, lockdownd_client_t client, con
49 np_client_t np; 49 np_client_t np;
50 50
51 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service); 51 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service);
52 if (service->port) { 52 if (service && service->port) {
53 printf("::::::::::::::: np was started ::::::::::::\n"); 53 printf("::::::::::::::: np was started ::::::::::::\n");
54 np_client_new(phone, service, &np); 54 np_client_new(phone, service, &np);
55 if (np) { 55 if (np) {
@@ -109,15 +109,10 @@ int main(int argc, char *argv[])
109 109
110 lockdownd_start_service(client, "com.apple.afc", &service); 110 lockdownd_start_service(client, "com.apple.afc", &service);
111 111
112 if (service->port) { 112 if (service && service->port) {
113 afc_client_t afc = NULL; 113 afc_client_t afc = NULL;
114 afc_client_new(phone, service, &afc); 114 afc_client_new(phone, service, &afc);
115 115
116 if (service) {
117 lockdownd_service_descriptor_free(service);
118 service = NULL;
119 }
120
121 if (afc) { 116 if (afc) {
122 service->port = 0; 117 service->port = 0;
123 service->ssl_enabled = 0; 118 service->ssl_enabled = 0;
@@ -129,11 +124,6 @@ int main(int argc, char *argv[])
129 printf("ERROR: Notification proxy could not be started.\n"); 124 printf("ERROR: Notification proxy could not be started.\n");
130 } 125 }
131 126
132 if (service) {
133 lockdownd_service_descriptor_free(service);
134 service = NULL;
135 }
136
137 if (gnp) { 127 if (gnp) {
138 const char *nspec[5] = { 128 const char *nspec[5] = {
139 NP_SYNC_CANCEL_REQUEST, 129 NP_SYNC_CANCEL_REQUEST,
@@ -266,6 +256,9 @@ int main(int argc, char *argv[])
266 } 256 }
267 257
268 afc_client_free(afc); 258 afc_client_free(afc);
259
260 lockdownd_service_descriptor_free(service);
261 service = NULL;
269 } else { 262 } else {
270 printf("Start service failure.\n"); 263 printf("Start service failure.\n");
271 } 264 }
diff --git a/src/afc.c b/src/afc.c
index d61032d..c281e2c 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -123,7 +123,7 @@ afc_error_t afc_client_new_with_service_client(service_client_t service_client,
123 */ 123 */
124afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t * client) 124afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t * client)
125{ 125{
126 if (!device || service->port == 0) 126 if (!device || !service || service->port == 0)
127 return AFC_E_INVALID_ARG; 127 return AFC_E_INVALID_ARG;
128 128
129 service_client_t parent = NULL; 129 service_client_t parent = NULL;
diff --git a/src/device_link_service.c b/src/device_link_service.c
index ac89211..2608b9f 100644
--- a/src/device_link_service.c
+++ b/src/device_link_service.c
@@ -84,7 +84,7 @@ static int device_link_service_get_message(plist_t dl_msg, char **message)
84 */ 84 */
85device_link_service_error_t device_link_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, device_link_service_client_t *client) 85device_link_service_error_t device_link_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, device_link_service_client_t *client)
86{ 86{
87 if (!device || service->port == 0 || !client || *client) { 87 if (!device || !service || service->port == 0 || !client || *client) {
88 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 88 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
89 } 89 }
90 90
diff --git a/src/diagnostics_relay.c b/src/diagnostics_relay.c
index 3469ae4..506b901 100644
--- a/src/diagnostics_relay.c
+++ b/src/diagnostics_relay.c
@@ -83,7 +83,7 @@ static int diagnostics_relay_check_result(plist_t dict)
83 */ 83 */
84diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client) 84diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client)
85{ 85{
86 if (!device || service->port == 0 || !client || *client) { 86 if (!device || !service || service->port == 0 || !client || *client) {
87 return DIAGNOSTICS_RELAY_E_INVALID_ARG; 87 return DIAGNOSTICS_RELAY_E_INVALID_ARG;
88 } 88 }
89 89
diff --git a/src/file_relay.c b/src/file_relay.c
index 39382fb..b1adb4f 100644
--- a/src/file_relay.c
+++ b/src/file_relay.c
@@ -38,7 +38,7 @@
38 */ 38 */
39file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client) 39file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client)
40{ 40{
41 if (!device || service->port == 0 || !client || *client) { 41 if (!device || !service || service->port == 0 || !client || *client) {
42 return FILE_RELAY_E_INVALID_ARG; 42 return FILE_RELAY_E_INVALID_ARG;
43 } 43 }
44 44
diff --git a/src/heartbeat.c b/src/heartbeat.c
index 0f8d2f3..cee852e 100644
--- a/src/heartbeat.c
+++ b/src/heartbeat.c
@@ -74,13 +74,13 @@ heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descr
74{ 74{
75 *client = NULL; 75 *client = NULL;
76 76
77 debug_info("Creating heartbeat_client, port = %d.", service->port); 77 if (!device || !service || service->port == 0 || !client || *client) {
78
79 if (!device || service->port == 0 || !client || *client) {
80 debug_info("Incorrect parameter passed to heartbeat_client_new."); 78 debug_info("Incorrect parameter passed to heartbeat_client_new.");
81 return HEARTBEAT_E_INVALID_ARG; 79 return HEARTBEAT_E_INVALID_ARG;
82 } 80 }
83 81
82 debug_info("Creating heartbeat_client, port = %d.", service->port);
83
84 property_list_service_client_t plclient = NULL; 84 property_list_service_client_t plclient = NULL;
85 heartbeat_error_t ret = heartbeat_error(property_list_service_client_new(device, service, &plclient)); 85 heartbeat_error_t ret = heartbeat_error(property_list_service_client_new(device, service, &plclient));
86 if (ret != HEARTBEAT_E_SUCCESS) { 86 if (ret != HEARTBEAT_E_SUCCESS) {
diff --git a/src/house_arrest.c b/src/house_arrest.c
index b3dbbf8..5dfd1b6 100644
--- a/src/house_arrest.c
+++ b/src/house_arrest.c
@@ -68,9 +68,6 @@ static house_arrest_error_t house_arrest_error(property_list_service_error_t err
68 */ 68 */
69house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client) 69house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client)
70{ 70{
71 if (!device)
72 return HOUSE_ARREST_E_INVALID_ARG;
73
74 property_list_service_client_t plistclient = NULL; 71 property_list_service_client_t plistclient = NULL;
75 house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, service, &plistclient)); 72 house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, service, &plistclient));
76 if (err != HOUSE_ARREST_E_SUCCESS) { 73 if (err != HOUSE_ARREST_E_SUCCESS) {
diff --git a/src/installation_proxy.c b/src/installation_proxy.c
index eacab9d..d4c1750 100644
--- a/src/installation_proxy.c
+++ b/src/installation_proxy.c
@@ -104,12 +104,10 @@ static instproxy_error_t instproxy_error(property_list_service_error_t err)
104 */ 104 */
105instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client) 105instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client)
106{ 106{
107 if (!device)
108 return INSTPROXY_E_INVALID_ARG;
109
110 property_list_service_client_t plistclient = NULL; 107 property_list_service_client_t plistclient = NULL;
111 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 108 instproxy_error_t err = instproxy_error(property_list_service_client_new(device, service, &plistclient));
112 return INSTPROXY_E_CONN_FAILED; 109 if (err != INSTPROXY_E_SUCCESS) {
110 return err;
113 } 111 }
114 112
115 instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); 113 instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private));
diff --git a/src/misagent.c b/src/misagent.c
index cb84188..1bc4519 100644
--- a/src/misagent.c
+++ b/src/misagent.c
@@ -100,9 +100,6 @@ static misagent_error_t misagent_check_result(plist_t response, int* status_code
100 */ 100 */
101misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client) 101misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client)
102{ 102{
103 if (!device)
104 return MISAGENT_E_INVALID_ARG;
105
106 property_list_service_client_t plistclient = NULL; 103 property_list_service_client_t plistclient = NULL;
107 misagent_error_t err = misagent_error(property_list_service_client_new(device, service, &plistclient)); 104 misagent_error_t err = misagent_error(property_list_service_client_new(device, service, &plistclient));
108 if (err != MISAGENT_E_SUCCESS) { 105 if (err != MISAGENT_E_SUCCESS) {
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c
index 3e31ef4..1d608db 100644
--- a/src/mobile_image_mounter.c
+++ b/src/mobile_image_mounter.c
@@ -98,12 +98,10 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser
98 */ 98 */
99mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client) 99mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client)
100{ 100{
101 if (!device)
102 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
103
104 property_list_service_client_t plistclient = NULL; 101 property_list_service_client_t plistclient = NULL;
105 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 102 mobile_image_mounter_error_t err = mobile_image_mounter_error(property_list_service_client_new(device, service, &plistclient));
106 return MOBILE_IMAGE_MOUNTER_E_CONN_FAILED; 103 if (err != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
104 return err;
107 } 105 }
108 106
109 mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); 107 mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private));
diff --git a/src/mobilebackup.c b/src/mobilebackup.c
index ab4dec0..aae4b06 100644
--- a/src/mobilebackup.c
+++ b/src/mobilebackup.c
@@ -72,10 +72,9 @@ static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)
72 * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if 72 * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if
73 * the mobilebackup version on the device is newer. 73 * the mobilebackup version on the device is newer.
74 */ 74 */
75mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, 75mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client)
76 mobilebackup_client_t * client)
77{ 76{
78 if (!device || service->port == 0 || !client || *client) 77 if (!device || !service || service->port == 0 || !client || *client)
79 return MOBILEBACKUP_E_INVALID_ARG; 78 return MOBILEBACKUP_E_INVALID_ARG;
80 79
81 device_link_service_client_t dlclient = NULL; 80 device_link_service_client_t dlclient = NULL;
diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c
index 15ba469..6356376 100644
--- a/src/mobilebackup2.c
+++ b/src/mobilebackup2.c
@@ -76,7 +76,7 @@ static mobilebackup2_error_t mobilebackup2_error(device_link_service_error_t err
76mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service, 76mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service,
77 mobilebackup2_client_t * client) 77 mobilebackup2_client_t * client)
78{ 78{
79 if (!device || service->port == 0 || !client || *client) 79 if (!device || !service || service->port == 0 || !client || *client)
80 return MOBILEBACKUP2_E_INVALID_ARG; 80 return MOBILEBACKUP2_E_INVALID_ARG;
81 81
82 device_link_service_client_t dlclient = NULL; 82 device_link_service_client_t dlclient = NULL;
diff --git a/src/mobilesync.c b/src/mobilesync.c
index 4fe24b2..af70ea4 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -81,7 +81,7 @@ static mobilesync_error_t mobilesync_error(device_link_service_error_t err)
81mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service, 81mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service,
82 mobilesync_client_t * client) 82 mobilesync_client_t * client)
83{ 83{
84 if (!device || service->port == 0 || !client || *client) 84 if (!device || !service || service->port == 0 || !client || *client)
85 return MOBILESYNC_E_INVALID_ARG; 85 return MOBILESYNC_E_INVALID_ARG;
86 86
87 device_link_service_client_t dlclient = NULL; 87 device_link_service_client_t dlclient = NULL;
diff --git a/src/notification_proxy.c b/src/notification_proxy.c
index 8fb9ad0..5b293f8 100644
--- a/src/notification_proxy.c
+++ b/src/notification_proxy.c
@@ -108,12 +108,10 @@ static np_error_t np_error(property_list_service_error_t err)
108 */ 108 */
109np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client) 109np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client)
110{ 110{
111 if (!device)
112 return NP_E_INVALID_ARG;
113
114 property_list_service_client_t plistclient = NULL; 111 property_list_service_client_t plistclient = NULL;
115 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 112 np_error_t err = np_error(property_list_service_client_new(device, service, &plistclient));
116 return NP_E_CONN_FAILED; 113 if (err != NP_E_SUCCESS) {
114 return err;
117 } 115 }
118 116
119 np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); 117 np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private));
diff --git a/src/property_list_service.c b/src/property_list_service.c
index 025a9bc..941f37e 100644
--- a/src/property_list_service.c
+++ b/src/property_list_service.c
@@ -68,7 +68,7 @@ static property_list_service_error_t service_to_property_list_service_error(serv
68 */ 68 */
69property_list_service_error_t property_list_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client) 69property_list_service_error_t property_list_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client)
70{ 70{
71 if (!device || (service->port == 0) || !client || *client) 71 if (!device || !service || service->port == 0 || !client || *client)
72 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 72 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
73 73
74 service_client_t parent = NULL; 74 service_client_t parent = NULL;
diff --git a/src/sbservices.c b/src/sbservices.c
index 6b1a4d1..00f2862 100644
--- a/src/sbservices.c
+++ b/src/sbservices.c
@@ -97,9 +97,6 @@ static sbservices_error_t sbservices_error(property_list_service_error_t err)
97 */ 97 */
98sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client) 98sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client)
99{ 99{
100 if (!device)
101 return SBSERVICES_E_INVALID_ARG;
102
103 property_list_service_client_t plistclient = NULL; 100 property_list_service_client_t plistclient = NULL;
104 sbservices_error_t err = sbservices_error(property_list_service_client_new(device, service, &plistclient)); 101 sbservices_error_t err = sbservices_error(property_list_service_client_new(device, service, &plistclient));
105 if (err != SBSERVICES_E_SUCCESS) { 102 if (err != SBSERVICES_E_SUCCESS) {
diff --git a/src/screenshotr.c b/src/screenshotr.c
index e2bc979..b538232 100644
--- a/src/screenshotr.c
+++ b/src/screenshotr.c
@@ -76,7 +76,7 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err)
76screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service, 76screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service,
77 screenshotr_client_t * client) 77 screenshotr_client_t * client)
78{ 78{
79 if (!device || service->port == 0 || !client || *client) 79 if (!device || !service || service->port == 0 || !client || *client)
80 return SCREENSHOTR_E_INVALID_ARG; 80 return SCREENSHOTR_E_INVALID_ARG;
81 81
82 device_link_service_client_t dlclient = NULL; 82 device_link_service_client_t dlclient = NULL;
diff --git a/src/service.c b/src/service.c
index 959c9fb..abd1696 100644
--- a/src/service.c
+++ b/src/service.c
@@ -66,7 +66,7 @@ static service_error_t idevice_to_service_error(idevice_error_t err)
66 */ 66 */
67service_error_t service_client_new(idevice_t device, lockdownd_service_descriptor_t service, service_client_t *client) 67service_error_t service_client_new(idevice_t device, lockdownd_service_descriptor_t service, service_client_t *client)
68{ 68{
69 if (!device || (service->port == 0) || !client || *client) 69 if (!device || !service || service->port == 0 || !client || *client)
70 return SERVICE_E_INVALID_ARG; 70 return SERVICE_E_INVALID_ARG;
71 71
72 /* Attempt connection */ 72 /* Attempt connection */
@@ -117,7 +117,7 @@ service_error_t service_client_factory_start_service(idevice_t device, const cha
117 lockdownd_start_service(lckd, service_name, &service); 117 lockdownd_start_service(lckd, service_name, &service);
118 lockdownd_client_free(lckd); 118 lockdownd_client_free(lckd);
119 119
120 if (service->port <= 0) { 120 if (!service || service->port == 0) {
121 debug_info("Could not start service %s!", service_name); 121 debug_info("Could not start service %s!", service_name);
122 return SERVICE_E_START_SERVICE_ERROR; 122 return SERVICE_E_START_SERVICE_ERROR;
123 } 123 }
diff --git a/src/webinspector.c b/src/webinspector.c
index fea26d4..aef6d6f 100644
--- a/src/webinspector.c
+++ b/src/webinspector.c
@@ -74,13 +74,13 @@ webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service
74{ 74{
75 *client = NULL; 75 *client = NULL;
76 76
77 debug_info("Creating webinspector_client, port = %d.", service->port); 77 if (!device || !service || service->port == 0 || !client || *client) {
78
79 if (!device || service->port == 0 || !client || *client) {
80 debug_info("Incorrect parameter passed to webinspector_client_new."); 78 debug_info("Incorrect parameter passed to webinspector_client_new.");
81 return WEBINSPECTOR_E_INVALID_ARG; 79 return WEBINSPECTOR_E_INVALID_ARG;
82 } 80 }
83 81
82 debug_info("Creating webinspector_client, port = %d.", service->port);
83
84 property_list_service_client_t plclient = NULL; 84 property_list_service_client_t plclient = NULL;
85 webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, service, &plclient)); 85 webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, service, &plclient));
86 if (ret != WEBINSPECTOR_E_SUCCESS) { 86 if (ret != WEBINSPECTOR_E_SUCCESS) {
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index 95c5694..8f5362c 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -755,7 +755,7 @@ static void do_post_notification(const char *notification)
755 } 755 }
756 756
757 lockdownd_start_service(client, NP_SERVICE_NAME, &service); 757 lockdownd_start_service(client, NP_SERVICE_NAME, &service);
758 if (service->port) { 758 if (service && service->port) {
759 np_client_new(device, service, &np); 759 np_client_new(device, service, &np);
760 if (np) { 760 if (np) {
761 np_post_notification(np, notification); 761 np_post_notification(np, notification);
@@ -937,7 +937,7 @@ int main(int argc, char *argv[])
937 /* start notification_proxy */ 937 /* start notification_proxy */
938 np_client_t np = NULL; 938 np_client_t np = NULL;
939 ret = lockdownd_start_service(client, NP_SERVICE_NAME, &service); 939 ret = lockdownd_start_service(client, NP_SERVICE_NAME, &service);
940 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { 940 if ((ret == LOCKDOWN_E_SUCCESS) && service && service->port) {
941 np_client_new(device, service, &np); 941 np_client_new(device, service, &np);
942 np_set_notify_callback(np, notify_cb, NULL); 942 np_set_notify_callback(np, notify_cb, NULL);
943 const char *noties[5] = { 943 const char *noties[5] = {
@@ -952,11 +952,6 @@ int main(int argc, char *argv[])
952 printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME); 952 printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME);
953 } 953 }
954 954
955 if (service) {
956 lockdownd_service_descriptor_free(service);
957 service = NULL;
958 }
959
960 afc_client_t afc = NULL; 955 afc_client_t afc = NULL;
961 if (cmd == CMD_BACKUP) { 956 if (cmd == CMD_BACKUP) {
962 /* start AFC, we need this for the lock file */ 957 /* start AFC, we need this for the lock file */
@@ -975,7 +970,7 @@ int main(int argc, char *argv[])
975 970
976 /* start mobilebackup service and retrieve port */ 971 /* start mobilebackup service and retrieve port */
977 ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &service); 972 ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &service);
978 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { 973 if ((ret == LOCKDOWN_E_SUCCESS) && service && service->port) {
979 printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, service->port); 974 printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, service->port);
980 mobilebackup_client_new(device, service, &mobilebackup); 975 mobilebackup_client_new(device, service, &mobilebackup);
981 976
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index 0353c9b..d70a7ae 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -489,7 +489,7 @@ static void do_post_notification(idevice_t device, const char *notification)
489 } 489 }
490 490
491 lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); 491 lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service);
492 if (service->port) { 492 if (service && service->port) {
493 np_client_new(device, service, &np); 493 np_client_new(device, service, &np);
494 if (np) { 494 if (np) {
495 np_post_notification(np, notification); 495 np_post_notification(np, notification);
@@ -1557,7 +1557,7 @@ int main(int argc, char *argv[])
1557 /* start notification_proxy */ 1557 /* start notification_proxy */
1558 np_client_t np = NULL; 1558 np_client_t np = NULL;
1559 ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); 1559 ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service);
1560 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { 1560 if ((ret == LOCKDOWN_E_SUCCESS) && service && service->port) {
1561 np_client_new(device, service, &np); 1561 np_client_new(device, service, &np);
1562 np_set_notify_callback(np, notify_cb, NULL); 1562 np_set_notify_callback(np, notify_cb, NULL);
1563 const char *noties[5] = { 1563 const char *noties[5] = {
@@ -1572,11 +1572,6 @@ int main(int argc, char *argv[])
1572 printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME); 1572 printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME);
1573 } 1573 }
1574 1574
1575 if (service) {
1576 lockdownd_service_descriptor_free(service);
1577 service = NULL;
1578 }
1579
1580 afc_client_t afc = NULL; 1575 afc_client_t afc = NULL;
1581 if (cmd == CMD_BACKUP) { 1576 if (cmd == CMD_BACKUP) {
1582 /* start AFC, we need this for the lock file */ 1577 /* start AFC, we need this for the lock file */
@@ -1596,7 +1591,7 @@ int main(int argc, char *argv[])
1596 /* start mobilebackup service and retrieve port */ 1591 /* start mobilebackup service and retrieve port */
1597 mobilebackup2_client_t mobilebackup2 = NULL; 1592 mobilebackup2_client_t mobilebackup2 = NULL;
1598 ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &service); 1593 ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &service);
1599 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { 1594 if ((ret == LOCKDOWN_E_SUCCESS) && service && service->port) {
1600 PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, service->port); 1595 PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, service->port);
1601 mobilebackup2_client_new(device, service, &mobilebackup2); 1596 mobilebackup2_client_new(device, service, &mobilebackup2);
1602 1597
diff --git a/tools/idevicedebugserverproxy.c b/tools/idevicedebugserverproxy.c
index 32438ad..3a25ebc 100644
--- a/tools/idevicedebugserverproxy.c
+++ b/tools/idevicedebugserverproxy.c
@@ -297,7 +297,7 @@ int main(int argc, char *argv[])
297 goto leave_cleanup; 297 goto leave_cleanup;
298 } 298 }
299 299
300 if ((lockdownd_start_service(lockdown, "com.apple.debugserver", &service) != LOCKDOWN_E_SUCCESS) || !service->port) { 300 if ((lockdownd_start_service(lockdown, "com.apple.debugserver", &service) != LOCKDOWN_E_SUCCESS) || !service || !service->port) {
301 fprintf(stderr, "Could not start com.apple.debugserver!\nPlease make sure to mount the developer disk image first.\n"); 301 fprintf(stderr, "Could not start com.apple.debugserver!\nPlease make sure to mount the developer disk image first.\n");
302 result = EXIT_FAILURE; 302 result = EXIT_FAILURE;
303 goto leave_cleanup; 303 goto leave_cleanup;
diff --git a/tools/idevicediagnostics.c b/tools/idevicediagnostics.c
index 410d054..464df20 100644
--- a/tools/idevicediagnostics.c
+++ b/tools/idevicediagnostics.c
@@ -188,7 +188,7 @@ int main(int argc, char **argv)
188 188
189 lockdownd_client_free(lockdown_client); 189 lockdownd_client_free(lockdown_client);
190 190
191 if ((ret == LOCKDOWN_E_SUCCESS) && (service->port > 0)) { 191 if ((ret == LOCKDOWN_E_SUCCESS) && service && (service->port > 0)) {
192 if (diagnostics_relay_client_new(device, service, &diagnostics_client) != DIAGNOSTICS_RELAY_E_SUCCESS) { 192 if (diagnostics_relay_client_new(device, service, &diagnostics_client) != DIAGNOSTICS_RELAY_E_SUCCESS) {
193 printf("Could not connect to diagnostics_relay!\n"); 193 printf("Could not connect to diagnostics_relay!\n");
194 result = -1; 194 result = -1;
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c
index 57a2e27..e57d83a 100644
--- a/tools/ideviceimagemounter.c
+++ b/tools/ideviceimagemounter.c
@@ -305,7 +305,7 @@ int main(int argc, char **argv)
305 305
306 lockdownd_start_service(lckd, "com.apple.mobile.mobile_image_mounter", &service); 306 lockdownd_start_service(lckd, "com.apple.mobile.mobile_image_mounter", &service);
307 307
308 if (service->port == 0) { 308 if (!service || service->port == 0) {
309 printf("ERROR: Could not start mobile_image_mounter service!\n"); 309 printf("ERROR: Could not start mobile_image_mounter service!\n");
310 goto leave; 310 goto leave;
311 } 311 }
@@ -323,7 +323,7 @@ int main(int argc, char **argv)
323 if (!list_mode) { 323 if (!list_mode) {
324 struct stat fst; 324 struct stat fst;
325 if ((lockdownd_start_service(lckd, "com.apple.afc", &service) != 325 if ((lockdownd_start_service(lckd, "com.apple.afc", &service) !=
326 LOCKDOWN_E_SUCCESS) || !service->port) { 326 LOCKDOWN_E_SUCCESS) || !service || !service->port) {
327 fprintf(stderr, "Could not start com.apple.afc!\n"); 327 fprintf(stderr, "Could not start com.apple.afc!\n");
328 goto leave; 328 goto leave;
329 } 329 }
diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c
index 23e7b41..d056dd0 100644
--- a/tools/idevicescreenshot.c
+++ b/tools/idevicescreenshot.c
@@ -83,7 +83,7 @@ int main(int argc, char **argv)
83 83
84 lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &service); 84 lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &service);
85 lockdownd_client_free(lckd); 85 lockdownd_client_free(lckd);
86 if (service->port > 0) { 86 if (service && service->port > 0) {
87 if (screenshotr_client_new(device, service, &shotr) != SCREENSHOTR_E_SUCCESS) { 87 if (screenshotr_client_new(device, service, &shotr) != SCREENSHOTR_E_SUCCESS) {
88 printf("Could not connect to screenshotr!\n"); 88 printf("Could not connect to screenshotr!\n");
89 } else { 89 } else {