diff options
Diffstat (limited to 'src/bplist.c')
| -rw-r--r-- | src/bplist.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/bplist.c b/src/bplist.c index 840e40c..897b90f 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -324,7 +324,8 @@ static plist_t parse_string_node(const char **bnode, uint64_t size) | |||
| 324 | static char *plist_utf16be_to_utf8(uint16_t *unistr, long len, long *items_read, long *items_written) | 324 | static char *plist_utf16be_to_utf8(uint16_t *unistr, long len, long *items_read, long *items_written) |
| 325 | { | 325 | { |
| 326 | if (!unistr || (len <= 0)) return NULL; | 326 | if (!unistr || (len <= 0)) return NULL; |
| 327 | char *outbuf; | 327 | char* outbuf; |
| 328 | char* outbuf_new; | ||
| 328 | int p = 0; | 329 | int p = 0; |
| 329 | long i = 0; | 330 | long i = 0; |
| 330 | 331 | ||
| @@ -332,6 +333,7 @@ static char *plist_utf16be_to_utf8(uint16_t *unistr, long len, long *items_read, | |||
| 332 | uint32_t w; | 333 | uint32_t w; |
| 333 | int read_lead_surrogate = 0; | 334 | int read_lead_surrogate = 0; |
| 334 | 335 | ||
| 336 | /* allocate with enough space */ | ||
| 335 | outbuf = (char*)malloc(4*(len+1)); | 337 | outbuf = (char*)malloc(4*(len+1)); |
| 336 | if (!outbuf) { | 338 | if (!outbuf) { |
| 337 | PLIST_BIN_ERR("%s: Could not allocate %" PRIu64 " bytes\n", __func__, (uint64_t)(4*(len+1))); | 339 | PLIST_BIN_ERR("%s: Could not allocate %" PRIu64 " bytes\n", __func__, (uint64_t)(4*(len+1))); |
| @@ -381,30 +383,29 @@ static char *plist_utf16be_to_utf8(uint16_t *unistr, long len, long *items_read, | |||
| 381 | } | 383 | } |
| 382 | outbuf[p] = 0; | 384 | outbuf[p] = 0; |
| 383 | 385 | ||
| 386 | /* reduce the size to the actual size */ | ||
| 387 | outbuf_new = realloc(outbuf, p+1); | ||
| 388 | if (outbuf_new) { | ||
| 389 | outbuf = outbuf_new; | ||
| 390 | } | ||
| 391 | |||
| 384 | return outbuf; | 392 | return outbuf; |
| 385 | } | 393 | } |
| 386 | 394 | ||
| 387 | static plist_t parse_unicode_node(const char **bnode, uint64_t size) | 395 | static plist_t parse_unicode_node(const char **bnode, uint64_t size) |
| 388 | { | 396 | { |
| 389 | plist_data_t data = plist_new_plist_data(); | 397 | plist_data_t data = plist_new_plist_data(); |
| 390 | char *tmpstr = NULL; | ||
| 391 | long items_read = 0; | 398 | long items_read = 0; |
| 392 | long items_written = 0; | 399 | long items_written = 0; |
| 393 | 400 | ||
| 394 | data->type = PLIST_STRING; | 401 | data->type = PLIST_STRING; |
| 395 | 402 | data->strval = plist_utf16be_to_utf8((uint16_t*)(*bnode), size, &items_read, &items_written); | |
| 396 | tmpstr = plist_utf16be_to_utf8((uint16_t*)(*bnode), size, &items_read, &items_written); | 403 | if (!data->strval) { |
| 397 | if (!tmpstr) { | ||
| 398 | plist_free_data(data); | 404 | plist_free_data(data); |
| 399 | return NULL; | 405 | return NULL; |
| 400 | } | 406 | } |
| 401 | tmpstr[items_written] = '\0'; | ||
| 402 | |||
| 403 | data->type = PLIST_STRING; | ||
| 404 | data->strval = realloc(tmpstr, items_written+1); | ||
| 405 | if (!data->strval) | ||
| 406 | data->strval = tmpstr; | ||
| 407 | data->length = items_written; | 407 | data->length = items_written; |
| 408 | |||
| 408 | return node_create(NULL, data); | 409 | return node_create(NULL, data); |
| 409 | } | 410 | } |
| 410 | 411 | ||
