summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-07-26 03:51:33 +0200
committerGravatar Nikias Bassen2021-07-26 03:51:33 +0200
commit19eca85f90d9950596e1c6021d7b0f89407f5d7f (patch)
tree98619caf6b9dabf61af38edf5740378ae7a7ba3d /src
parent93622ece5bfd0c3e2e37c3ae643411c0284da9c8 (diff)
downloadlibimobiledevice-19eca85f90d9950596e1c6021d7b0f89407f5d7f.tar.gz
libimobiledevice-19eca85f90d9950596e1c6021d7b0f89407f5d7f.tar.bz2
idevice: Remove unnecessary memcpy from internal_ssl_read()
Diffstat (limited to 'src')
-rw-r--r--src/idevice.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/src/idevice.c b/src/idevice.c
index a2a4d0b..e67a649 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -811,24 +811,19 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **u
811 */ 811 */
812static ssize_t internal_ssl_read(idevice_connection_t connection, char *buffer, size_t length) 812static ssize_t internal_ssl_read(idevice_connection_t connection, char *buffer, size_t length)
813{ 813{
814 int bytes = 0, pos_start_fill = 0; 814 uint32_t bytes = 0;
815 size_t tbytes = 0; 815 uint32_t pos = 0;
816 int this_len = length;
817 idevice_error_t res; 816 idevice_error_t res;
818 char *recv_buffer;
819
820 debug_info("pre-read client wants %zi bytes", length);
821
822 recv_buffer = (char *)malloc(sizeof(char) * this_len);
823
824 unsigned int timeout = connection->ssl_recv_timeout; 817 unsigned int timeout = connection->ssl_recv_timeout;
825 818
819 debug_info("pre-read length = %zi bytes", length);
820
826 /* repeat until we have the full data or an error occurs */ 821 /* repeat until we have the full data or an error occurs */
827 do { 822 do {
828 if (timeout == (unsigned int)-1) { 823 if (timeout == (unsigned int)-1) {
829 res = internal_connection_receive(connection, recv_buffer, this_len, (uint32_t*)&bytes); 824 res = internal_connection_receive(connection, buffer + pos, (uint32_t)length - pos, &bytes);
830 } else { 825 } else {
831 res = internal_connection_receive_timeout(connection, recv_buffer, this_len, (uint32_t*)&bytes, (unsigned int)timeout); 826 res = internal_connection_receive_timeout(connection, buffer + pos, (uint32_t)length - pos, &bytes, (unsigned int)timeout);
832 } 827 }
833 if (res != IDEVICE_E_SUCCESS) { 828 if (res != IDEVICE_E_SUCCESS) {
834 if (res != IDEVICE_E_TIMEOUT) { 829 if (res != IDEVICE_E_TIMEOUT) {
@@ -837,27 +832,18 @@ static ssize_t internal_ssl_read(idevice_connection_t connection, char *buffer,
837 connection->status = res; 832 connection->status = res;
838 return -1; 833 return -1;
839 } 834 }
840 debug_info("post-read we got %i bytes", bytes); 835 debug_info("read %i bytes", bytes);
841 836
842 /* increase read count */ 837 /* increase read count */
843 tbytes += bytes; 838 pos += bytes;
844 839 if (pos < (uint32_t)length) {
845 /* fill the buffer with what we got right now */ 840 debug_info("re-read trying to read missing %i bytes", (uint32_t)length - pos);
846 memcpy(buffer + pos_start_fill, recv_buffer, bytes);
847 pos_start_fill += bytes;
848
849 if (tbytes >= length) {
850 break;
851 } 841 }
842 } while (pos < (uint32_t)length);
852 843
853 this_len = length - tbytes; 844 debug_info("post-read received %i bytes", bytes);
854 debug_info("re-read trying to read missing %i bytes", this_len);
855 } while (tbytes < length);
856 845
857 if (recv_buffer) { 846 return pos;
858 free(recv_buffer);
859 }
860 return tbytes;
861} 847}
862 848
863/** 849/**
@@ -867,7 +853,7 @@ static ssize_t internal_ssl_write(idevice_connection_t connection, const char *b
867{ 853{
868 uint32_t bytes = 0; 854 uint32_t bytes = 0;
869 idevice_error_t res; 855 idevice_error_t res;
870 debug_info("pre-send length = %zi", length); 856 debug_info("pre-send length = %zi bytes", length);
871 if ((res = internal_connection_send(connection, buffer, length, &bytes)) != IDEVICE_E_SUCCESS) { 857 if ((res = internal_connection_send(connection, buffer, length, &bytes)) != IDEVICE_E_SUCCESS) {
872 debug_info("ERROR: internal_connection_send returned %d", res); 858 debug_info("ERROR: internal_connection_send returned %d", res);
873 connection->status = res; 859 connection->status = res;
@@ -1220,7 +1206,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_disable_bypass_ssl(idevi
1220 if ((ssl_error = SSL_get_error(connection->ssl_data->session, 0)) == SSL_ERROR_NONE) { 1206 if ((ssl_error = SSL_get_error(connection->ssl_data->session, 0)) == SSL_ERROR_NONE) {
1221 SSL_shutdown(connection->ssl_data->session); 1207 SSL_shutdown(connection->ssl_data->session);
1222 } else { 1208 } else {
1223 debug_info("Skipping bidirectional SSL shutdown. SSL error code: %i\n", ssl_error); 1209 debug_info("Skipping bidirectional SSL shutdown. SSL error code: %i", ssl_error);
1224 } 1210 }
1225 } 1211 }
1226 } 1212 }