diff options
| author | 2013-10-09 14:34:10 +0200 | |
|---|---|---|
| committer | 2013-10-09 14:34:10 +0200 | |
| commit | 764384da9f8ed85abf5c22e05ab77acfad010b24 (patch) | |
| tree | bf4a6d4f230de0d3e48a11faab18fb85552d055b | |
| parent | f5425a9e9acdf9d6b59461a083e9da8c52be6df1 (diff) | |
| download | libimobiledevice-764384da9f8ed85abf5c22e05ab77acfad010b24.tar.gz libimobiledevice-764384da9f8ed85abf5c22e05ab77acfad010b24.tar.bz2 | |
property_list_service: improve error checking on receive
| -rw-r--r-- | src/property_list_service.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/property_list_service.c b/src/property_list_service.c index 28739c7..ea117af 100644 --- a/src/property_list_service.c +++ b/src/property_list_service.c | |||
| @@ -223,6 +223,7 @@ static property_list_service_error_t internal_plist_receive_timeout(property_lis | |||
| 223 | return PROPERTY_LIST_SERVICE_E_INVALID_ARG; | 223 | return PROPERTY_LIST_SERVICE_E_INVALID_ARG; |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | *plist = NULL; | ||
| 226 | service_error_t serr = service_receive_with_timeout(client->parent, (char*)&pktlen, sizeof(pktlen), &bytes, timeout); | 227 | service_error_t serr = service_receive_with_timeout(client->parent, (char*)&pktlen, sizeof(pktlen), &bytes, timeout); |
| 227 | if ((serr == SERVICE_E_SUCCESS) && (bytes == 0)) { | 228 | if ((serr == SERVICE_E_SUCCESS) && (bytes == 0)) { |
| 228 | return PROPERTY_LIST_SERVICE_E_TIMEOUT; | 229 | return PROPERTY_LIST_SERVICE_E_TIMEOUT; |
| @@ -238,6 +239,10 @@ static property_list_service_error_t internal_plist_receive_timeout(property_lis | |||
| 238 | char *content = NULL; | 239 | char *content = NULL; |
| 239 | debug_info("%d bytes following", pktlen); | 240 | debug_info("%d bytes following", pktlen); |
| 240 | content = (char*)malloc(pktlen); | 241 | content = (char*)malloc(pktlen); |
| 242 | if (!content) { | ||
| 243 | debug_info("out of memory when allocating %d bytes\n", pktlen); | ||
| 244 | return PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR; | ||
| 245 | } | ||
| 241 | 246 | ||
| 242 | while (curlen < pktlen) { | 247 | while (curlen < pktlen) { |
| 243 | service_receive(client->parent, content+curlen, pktlen-curlen, &bytes); | 248 | service_receive(client->parent, content+curlen, pktlen-curlen, &bytes); |
| @@ -248,15 +253,27 @@ static property_list_service_error_t internal_plist_receive_timeout(property_lis | |||
| 248 | debug_info("received %d bytes", bytes); | 253 | debug_info("received %d bytes", bytes); |
| 249 | curlen += bytes; | 254 | curlen += bytes; |
| 250 | } | 255 | } |
| 251 | if (!memcmp(content, "bplist00", 8)) { | 256 | if (curlen < pktlen) { |
| 257 | debug_info("received incomplete packet (%d of %d bytes)\n", curlen, pktlen); | ||
| 258 | if (curlen > 0) { | ||
| 259 | debug_info("incomplete packet following:"); | ||
| 260 | debug_buffer(content, curlen); | ||
| 261 | } | ||
| 262 | free(content); | ||
| 263 | return res; | ||
| 264 | } | ||
| 265 | if ((pktlen > 8) && !memcmp(content, "bplist00", 8)) { | ||
| 252 | plist_from_bin(content, pktlen, plist); | 266 | plist_from_bin(content, pktlen, plist); |
| 253 | } else { | 267 | } else if ((pktlen > 5) && !memcmp(content, "<?xml", 5)) { |
| 254 | /* iOS 4.3+ hack: plist data might contain invalid characters, thus we convert those to spaces */ | 268 | /* iOS 4.3+ hack: plist data might contain invalid characters, thus we convert those to spaces */ |
| 255 | for (bytes = 0; bytes < pktlen-1; bytes++) { | 269 | for (bytes = 0; bytes < pktlen-1; bytes++) { |
| 256 | if ((content[bytes] >= 0) && (content[bytes] < 0x20) && (content[bytes] != 0x09) && (content[bytes] != 0x0a) && (content[bytes] != 0x0d)) | 270 | if ((content[bytes] >= 0) && (content[bytes] < 0x20) && (content[bytes] != 0x09) && (content[bytes] != 0x0a) && (content[bytes] != 0x0d)) |
| 257 | content[bytes] = 0x20; | 271 | content[bytes] = 0x20; |
| 258 | } | 272 | } |
| 259 | plist_from_xml(content, pktlen, plist); | 273 | plist_from_xml(content, pktlen, plist); |
| 274 | } else { | ||
| 275 | debug_info("WARNING: received unexpected non-plist content"); | ||
| 276 | debug_buffer(content, pktlen); | ||
| 260 | } | 277 | } |
| 261 | if (*plist) { | 278 | if (*plist) { |
| 262 | debug_plist(*plist); | 279 | debug_plist(*plist); |
