diff options
author | Nikias Bassen | 2019-09-29 17:10:46 +0200 |
---|---|---|
committer | Nikias Bassen | 2019-09-29 17:10:46 +0200 |
commit | 60823f9eeb3f09cd8083f613522d01e21d2f6d2d (patch) | |
tree | 09eb401a998e3e7a2443affcb4ab1daa8a82ec0a /src | |
parent | 656b96ca6caac90eb78266bd1fabe7b76bcb8c03 (diff) | |
download | libimobiledevice-60823f9eeb3f09cd8083f613522d01e21d2f6d2d.tar.gz libimobiledevice-60823f9eeb3f09cd8083f613522d01e21d2f6d2d.tar.bz2 |
idevice: properly handle partial SSL writes
Diffstat (limited to 'src')
-rw-r--r-- | src/idevice.c | 23 |
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_ } if (connection->ssl_data) { + uint32_t sent = 0; + while (sent < len) { #ifdef HAVE_OPENSSL - int sent = SSL_write(connection->ssl_data->session, (const void*)data, (int)len); - debug_info("SSL_write %d, sent %d", len, sent); + int s = SSL_write(connection->ssl_data->session, (const void*)(data+sent), (int)(len-sent)); #else - ssize_t sent = gnutls_record_send(connection->ssl_data->session, (void*)data, (size_t)len); + ssize_t s = gnutls_record_send(connection->ssl_data->session, (void*)(data+sent), (size_t)(len-sent)); #endif - if ((uint32_t)sent == (uint32_t)len) { - *sent_bytes = sent; - return IDEVICE_E_SUCCESS; + if (s < 0) { + break; + } + sent += s; } - *sent_bytes = 0; - return IDEVICE_E_SSL_ERROR; + debug_info("SSL_write %d, sent %d", len, sent); + if (sent < len) { + *sent_bytes = 0; + return IDEVICE_E_SSL_ERROR; + } + *sent_bytes = sent; + return IDEVICE_E_SUCCESS; } return internal_connection_send(connection, data, len, sent_bytes); } |