summaryrefslogtreecommitdiffstats
path: root/src/idevice.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-09-29 17:10:46 +0200
committerGravatar Nikias Bassen2019-09-29 17:10:46 +0200
commit60823f9eeb3f09cd8083f613522d01e21d2f6d2d (patch)
tree09eb401a998e3e7a2443affcb4ab1daa8a82ec0a /src/idevice.c
parent656b96ca6caac90eb78266bd1fabe7b76bcb8c03 (diff)
downloadlibimobiledevice-60823f9eeb3f09cd8083f613522d01e21d2f6d2d.tar.gz
libimobiledevice-60823f9eeb3f09cd8083f613522d01e21d2f6d2d.tar.bz2
idevice: properly handle partial SSL writes
Diffstat (limited to 'src/idevice.c')
-rw-r--r--src/idevice.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/idevice.c b/src/idevice.c
index 90b531d..06991c5 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -384,18 +384,25 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_send(idevice_connection_
384 } 384 }
385 385
386 if (connection->ssl_data) { 386 if (connection->ssl_data) {
387 uint32_t sent = 0;
388 while (sent < len) {
387#ifdef HAVE_OPENSSL 389#ifdef HAVE_OPENSSL
388 int sent = SSL_write(connection->ssl_data->session, (const void*)data, (int)len); 390 int s = SSL_write(connection->ssl_data->session, (const void*)(data+sent), (int)(len-sent));
389 debug_info("SSL_write %d, sent %d", len, sent);
390#else 391#else
391 ssize_t sent = gnutls_record_send(connection->ssl_data->session, (void*)data, (size_t)len); 392 ssize_t s = gnutls_record_send(connection->ssl_data->session, (void*)(data+sent), (size_t)(len-sent));
392#endif 393#endif
393 if ((uint32_t)sent == (uint32_t)len) { 394 if (s < 0) {
394 *sent_bytes = sent; 395 break;
395 return IDEVICE_E_SUCCESS; 396 }
397 sent += s;
396 } 398 }
397 *sent_bytes = 0; 399 debug_info("SSL_write %d, sent %d", len, sent);
398 return IDEVICE_E_SSL_ERROR; 400 if (sent < len) {
401 *sent_bytes = 0;
402 return IDEVICE_E_SSL_ERROR;
403 }
404 *sent_bytes = sent;
405 return IDEVICE_E_SUCCESS;
399 } 406 }
400 return internal_connection_send(connection, data, len, sent_bytes); 407 return internal_connection_send(connection, data, len, sent_bytes);
401} 408}