diff options
| author | 2009-04-22 20:17:55 +0200 | |
|---|---|---|
| committer | 2009-04-23 19:04:41 -0700 | |
| commit | fa8424a5da3d9e745541834048a5bbbfd5427a5c (patch) | |
| tree | a97da763985dccd161b0bceb86f540c4c54672ac /src | |
| parent | 63e5eed5542c8c85144ee0ac20174c0859fab866 (diff) | |
| download | libimobiledevice-fa8424a5da3d9e745541834048a5bbbfd5427a5c.tar.gz libimobiledevice-fa8424a5da3d9e745541834048a5bbbfd5427a5c.tar.bz2 | |
Fix receive of plists larger than a packet for lockdown and MobileSync
[#35 state:resolved]
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src')
| -rw-r--r-- | src/MobileSync.c | 20 | ||||
| -rw-r--r-- | src/lockdown.c | 30 |
2 files changed, 36 insertions, 14 deletions
diff --git a/src/MobileSync.c b/src/MobileSync.c index b16a51b..25f9473 100644 --- a/src/MobileSync.c +++ b/src/MobileSync.c | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "MobileSync.h" | 22 | #include "MobileSync.h" |
| 23 | #include <plist/plist.h> | 23 | #include <plist/plist.h> |
| 24 | #include <string.h> | 24 | #include <string.h> |
| 25 | #include <arpa/inet.h> | ||
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | #define MSYNC_VERSION_INT1 100 | 28 | #define MSYNC_VERSION_INT1 100 |
| @@ -136,16 +137,27 @@ iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist) | |||
| 136 | if (!client || !plist || (plist && *plist)) | 137 | if (!client || !plist || (plist && *plist)) |
| 137 | return IPHONE_E_INVALID_ARG; | 138 | return IPHONE_E_INVALID_ARG; |
| 138 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 139 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 139 | char *receive; | 140 | char *receive = NULL; |
| 140 | uint32_t datalen = 0, bytes = 0; | 141 | uint32_t datalen = 0, bytes = 0, received_bytes = 0; |
| 141 | 142 | ||
| 142 | ret = iphone_mux_recv(client->connection, (char *) &datalen, sizeof(datalen), &bytes); | 143 | ret = iphone_mux_recv(client->connection, (char *) &datalen, sizeof(datalen), &bytes); |
| 143 | datalen = ntohl(datalen); | 144 | datalen = ntohl(datalen); |
| 144 | 145 | ||
| 145 | receive = (char *) malloc(sizeof(char) * datalen); | 146 | receive = (char *) malloc(sizeof(char) * datalen); |
| 146 | ret = iphone_mux_recv(client->connection, receive, datalen, &bytes); | ||
| 147 | 147 | ||
| 148 | plist_from_bin(receive, bytes, plist); | 148 | /* fill buffer and request more packets if needed */ |
| 149 | while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { | ||
| 150 | ret = iphone_mux_recv(client->connection, receive + received_bytes, datalen - received_bytes, &bytes); | ||
| 151 | received_bytes += bytes; | ||
| 152 | } | ||
| 153 | |||
| 154 | if (ret != IPHONE_E_SUCCESS) { | ||
| 155 | free(receive); | ||
| 156 | return ret; | ||
| 157 | } | ||
| 158 | |||
| 159 | plist_from_bin(receive, received_bytes, plist); | ||
| 160 | free(receive); | ||
| 149 | 161 | ||
| 150 | char *XMLContent = NULL; | 162 | char *XMLContent = NULL; |
| 151 | uint32_t length = 0; | 163 | uint32_t length = 0; |
diff --git a/src/lockdown.c b/src/lockdown.c index e3636d1..64c325e 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -193,8 +193,8 @@ iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist) | |||
| 193 | if (!client || !plist || (plist && *plist)) | 193 | if (!client || !plist || (plist && *plist)) |
| 194 | return IPHONE_E_INVALID_ARG; | 194 | return IPHONE_E_INVALID_ARG; |
| 195 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 195 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 196 | char *receive; | 196 | char *receive = NULL; |
| 197 | uint32_t datalen = 0, bytes = 0; | 197 | uint32_t datalen = 0, bytes = 0, received_bytes = 0; |
| 198 | 198 | ||
| 199 | if (!client->in_SSL) | 199 | if (!client->in_SSL) |
| 200 | ret = iphone_mux_recv(client->connection, (char *) &datalen, sizeof(datalen), &bytes); | 200 | ret = iphone_mux_recv(client->connection, (char *) &datalen, sizeof(datalen), &bytes); |
| @@ -206,21 +206,31 @@ iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist) | |||
| 206 | datalen = ntohl(datalen); | 206 | datalen = ntohl(datalen); |
| 207 | 207 | ||
| 208 | receive = (char *) malloc(sizeof(char) * datalen); | 208 | receive = (char *) malloc(sizeof(char) * datalen); |
| 209 | if (!client->in_SSL) | 209 | |
| 210 | ret = iphone_mux_recv(client->connection, receive, datalen, &bytes); | 210 | if (!client->in_SSL) { |
| 211 | else { | 211 | /* fill buffer and request more packets if needed */ |
| 212 | bytes = gnutls_record_recv(*client->ssl_session, receive, datalen); | 212 | while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { |
| 213 | if (bytes > 0) | 213 | ret = iphone_mux_recv(client->connection, receive + received_bytes, datalen - received_bytes, &bytes); |
| 214 | received_bytes += bytes; | ||
| 215 | } | ||
| 216 | } else { | ||
| 217 | received_bytes = gnutls_record_recv(*client->ssl_session, receive, datalen); | ||
| 218 | if (received_bytes > 0) | ||
| 214 | ret = IPHONE_E_SUCCESS; | 219 | ret = IPHONE_E_SUCCESS; |
| 215 | } | 220 | } |
| 216 | 221 | ||
| 217 | if (bytes <= 0) { | 222 | if (ret != IPHONE_E_SUCCESS) { |
| 223 | free(receive); | ||
| 224 | return ret; | ||
| 225 | } | ||
| 226 | |||
| 227 | if (received_bytes <= 0) { | ||
| 218 | free(receive); | 228 | free(receive); |
| 219 | return IPHONE_E_NOT_ENOUGH_DATA; | 229 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 220 | } | 230 | } |
| 221 | 231 | ||
| 222 | log_dbg_msg(DBGMASK_LOCKDOWND, "Recv msg :\nsize : %i\nbuffer :\n%s\n", bytes, receive); | 232 | log_dbg_msg(DBGMASK_LOCKDOWND, "Recv msg :\nsize : %i\nbuffer :\n%s\n", received_bytes, receive); |
| 223 | plist_from_xml(receive, bytes, plist); | 233 | plist_from_xml(receive, received_bytes, plist); |
| 224 | free(receive); | 234 | free(receive); |
| 225 | 235 | ||
| 226 | if (!*plist) | 236 | if (!*plist) |
