diff options
| author | 2017-02-05 05:16:09 +0100 | |
|---|---|---|
| committer | 2017-02-05 05:16:09 +0100 | |
| commit | 8e51cdc2c2bcd3bbed629ce76be055147c9ddbed (patch) | |
| tree | f450b937a2a0407504f1ac3fcd89963234c3209d | |
| parent | 2c44cd6e7d3b961dd237b74a24cbaa80b3efc7a9 (diff) | |
| download | libplist-8e51cdc2c2bcd3bbed629ce76be055147c9ddbed.tar.gz libplist-8e51cdc2c2bcd3bbed629ce76be055147c9ddbed.tar.bz2 | |
bplist: Make sure the offset table is in the correct range
| -rw-r--r-- | src/bplist.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/bplist.c b/src/bplist.c index d83f700..cdfea80 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -679,7 +679,9 @@ PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * | |||
| 679 | uint8_t ref_size = 0; | 679 | uint8_t ref_size = 0; |
| 680 | uint64_t num_objects = 0; | 680 | uint64_t num_objects = 0; |
| 681 | uint64_t root_object = 0; | 681 | uint64_t root_object = 0; |
| 682 | char *offset_table = NULL; | 682 | const char *offset_table = NULL; |
| 683 | const char *start_data = NULL; | ||
| 684 | const char *end_data = NULL; | ||
| 683 | 685 | ||
| 684 | //first check we have enough data | 686 | //first check we have enough data |
| 685 | if (!(length >= BPLIST_MAGIC_SIZE + BPLIST_VERSION_SIZE + sizeof(bplist_trailer_t))) | 687 | if (!(length >= BPLIST_MAGIC_SIZE + BPLIST_VERSION_SIZE + sizeof(bplist_trailer_t))) |
| @@ -691,8 +693,11 @@ PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * | |||
| 691 | if (memcmp(plist_bin + BPLIST_MAGIC_SIZE, BPLIST_VERSION, BPLIST_VERSION_SIZE) != 0) | 693 | if (memcmp(plist_bin + BPLIST_MAGIC_SIZE, BPLIST_VERSION, BPLIST_VERSION_SIZE) != 0) |
| 692 | return; | 694 | return; |
| 693 | 695 | ||
| 696 | start_data = plist_bin + BPLIST_MAGIC_SIZE + BPLIST_VERSION_SIZE; | ||
| 697 | end_data = plist_bin + length - sizeof(bplist_trailer_t); | ||
| 698 | |||
| 694 | //now parse trailer | 699 | //now parse trailer |
| 695 | trailer = (bplist_trailer_t*)(plist_bin + (length - sizeof(bplist_trailer_t))); | 700 | trailer = (bplist_trailer_t*)end_data; |
| 696 | 701 | ||
| 697 | offset_size = trailer->offset_size; | 702 | offset_size = trailer->offset_size; |
| 698 | ref_size = trailer->ref_size; | 703 | ref_size = trailer->ref_size; |
| @@ -712,10 +717,10 @@ PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * | |||
| 712 | if (root_object >= num_objects) | 717 | if (root_object >= num_objects) |
| 713 | return; | 718 | return; |
| 714 | 719 | ||
| 715 | if (offset_table < plist_bin || offset_table >= plist_bin + length) | 720 | if (offset_table < start_data || offset_table >= end_data) |
| 716 | return; | 721 | return; |
| 717 | 722 | ||
| 718 | if (offset_table + num_objects * offset_size >= plist_bin + length) | 723 | if (offset_table + num_objects * offset_size > end_data) |
| 719 | return; | 724 | return; |
| 720 | 725 | ||
| 721 | struct bplist_data bplist; | 726 | struct bplist_data bplist; |
