diff options
| author | 2017-02-01 20:22:38 +0100 | |
|---|---|---|
| committer | 2017-02-01 20:22:38 +0100 | |
| commit | 4765d9a60ca4248a8f89289271ac69cbffcc29bc (patch) | |
| tree | 93f86049f659d89d63a6d1163844e8ad6e7a0bdb /src/bplist.c | |
| parent | 5791fb908a5f4e3ae39f8c4644dc7f0291f0e80f (diff) | |
| download | libplist-4765d9a60ca4248a8f89289271ac69cbffcc29bc.tar.gz libplist-4765d9a60ca4248a8f89289271ac69cbffcc29bc.tar.bz2 | |
bplist: Fix possible out-of-bounds read in parse_array_node() with proper bounds checking
Diffstat (limited to 'src/bplist.c')
| -rw-r--r-- | src/bplist.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/bplist.c b/src/bplist.c index 2e32f70..a73f1ee 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -447,10 +447,11 @@ static plist_t parse_dict_node(struct bplist_data *bplist, const char** bnode, u | |||
| 447 | static plist_t parse_array_node(struct bplist_data *bplist, const char** bnode, uint64_t size) | 447 | static plist_t parse_array_node(struct bplist_data *bplist, const char** bnode, uint64_t size) |
| 448 | { | 448 | { |
| 449 | uint64_t j; | 449 | uint64_t j; |
| 450 | uint32_t str_j = 0; | 450 | uint64_t str_j = 0; |
| 451 | uint32_t index1; | 451 | uint64_t index1; |
| 452 | |||
| 453 | plist_data_t data = plist_new_plist_data(); | 452 | plist_data_t data = plist_new_plist_data(); |
| 453 | const char *const end_data = bplist->data + bplist->size; | ||
| 454 | const char *index1_ptr = NULL; | ||
| 454 | 455 | ||
| 455 | data->type = PLIST_ARRAY; | 456 | data->type = PLIST_ARRAY; |
| 456 | data->length = size; | 457 | data->length = size; |
| @@ -459,7 +460,14 @@ static plist_t parse_array_node(struct bplist_data *bplist, const char** bnode, | |||
| 459 | 460 | ||
| 460 | for (j = 0; j < data->length; j++) { | 461 | for (j = 0; j < data->length; j++) { |
| 461 | str_j = j * bplist->ref_size; | 462 | str_j = j * bplist->ref_size; |
| 462 | index1 = UINT_TO_HOST((*bnode) + str_j, bplist->ref_size); | 463 | index1_ptr = (*bnode) + str_j; |
| 464 | |||
| 465 | if (index1_ptr < bplist->data || index1_ptr + bplist->ref_size >= end_data) { | ||
| 466 | plist_free(node); | ||
| 467 | return NULL; | ||
| 468 | } | ||
| 469 | |||
| 470 | index1 = UINT_TO_HOST(index1_ptr, bplist->ref_size); | ||
| 463 | 471 | ||
| 464 | if (index1 >= bplist->num_objects) { | 472 | if (index1 >= bplist->num_objects) { |
| 465 | plist_free(node); | 473 | plist_free(node); |
