diff options
author | Paulo Alcantara <pcacjr@gmail.com> | 2012-01-18 21:18:25 -0300 |
---|---|---|
committer | Paulo Alcantara <pcacjr@gmail.com> | 2012-02-11 16:06:07 -0300 |
commit | 77f467ca6a200e64a13c23bf38e7513b80b811de (patch) | |
tree | cbeb353733a6c0d49f0302a03211bbe4018fbfde | |
parent | 2716df8069f8df9cb9bbae2682fe089fadd8253f (diff) | |
download | syslinux-77f467ca6a200e64a13c23bf38e7513b80b811de.tar.gz |
ntfs: handle offsets when walking through attribute list's entries
Instead of either hanging out or printing a fatal message on the screen
when not finding attributes from attribute list's entries, handle
offsets that will determine if we reached end of a attribute list.
Signed-off-by: Paulo Alcantara <pcacjr@gmail.com>
-rw-r--r-- | core/fs/ntfs/ntfs.c | 33 | ||||
-rw-r--r-- | core/fs/ntfs/ntfs.h | 5 |
2 files changed, 21 insertions, 17 deletions
diff --git a/core/fs/ntfs/ntfs.c b/core/fs/ntfs/ntfs.c index f64c8c82..c51f1f99 100644 --- a/core/fs/ntfs/ntfs.c +++ b/core/fs/ntfs/ntfs.c @@ -420,6 +420,7 @@ ntfs_attr_list_lookup(struct fs_info *fs, struct ntfs_attr_record *attr, int64_t last_lcn; block_t blk; struct ntfs_attr_list_entry *attr_entry; + uint32_t len = 0; struct ntfs_mft_record *mrec; uint64_t start_blk = 0; @@ -428,16 +429,18 @@ ntfs_attr_list_lookup(struct fs_info *fs, struct ntfs_attr_record *attr, attr_entry = (struct ntfs_attr_list_entry *) ((uint8_t *)attr + attr->data.resident.value_offset); - for (;; attr_entry = (struct ntfs_attr_list_entry *)((uint8_t *)attr_entry + - attr_entry->length)) { + len = attr->data.resident.value_len; + for (; (uint8_t *)attr_entry < (uint8_t *)attr + len; + attr_entry = (struct ntfs_attr_list_entry *)((uint8_t *)attr_entry + + attr_entry->length)) { + dprintf("<$ATTRIBUTE_LIST> Attribute type: 0x%X\n", + attr_entry->type); if (attr_entry->type == type) - goto found; + goto found; /* We got the attribute! :-) */ } - /* You should never reach here! If you did, so you do have a bogus - * NTFS drive. Fix it. - */ - goto fatal_error; + printf("No attribute found.\n"); + goto out; handle_non_resident_attr: attr_len = (uint8_t *)attr + attr->len; @@ -470,8 +473,12 @@ handle_non_resident_attr: } attr_entry = (struct ntfs_attr_list_entry *)&buf; - for (;; attr_entry = (struct ntfs_attr_list_entry *) + len = attr->data.non_resident.data_size; + for (; (uint8_t *)attr_entry < (uint8_t *)&buf[0] + len; + attr_entry = (struct ntfs_attr_list_entry *) ((uint8_t *)attr_entry + attr_entry->length)) { + printf("<$ATTRIBUTE_LIST> Attribute type: 0x%x\n", + attr_entry->type); if (attr_entry->type == type) goto found; /* We got the attribute! :-) */ } @@ -483,10 +490,7 @@ handle_non_resident_attr: } } while (!(chunk.flags & MAP_END)); - /* You should never reach here! If you did, so you do have a bogus - * NTFS drive. Fix it. - */ - goto fatal_error; + printf("No attribute found.\n"); out: return NULL; @@ -504,11 +508,6 @@ found: /* return the found MFT record */ return mrec; - -fatal_error: - printf("(FATAL) You have a bogus NTFS drive installed in your system. " - "Fix it!\n"); - goto out; } static struct ntfs_attr_record * diff --git a/core/fs/ntfs/ntfs.h b/core/fs/ntfs/ntfs.h index 8a885b65..3f2b260d 100644 --- a/core/fs/ntfs/ntfs.h +++ b/core/fs/ntfs/ntfs.h @@ -292,6 +292,11 @@ struct ntfs_attr_record { uint8_t compression_unit; uint8_t reserved[5]; int64_t allocated_size; + int64_t data_size; /* Byte size of the attribute value. + * Note: it can be larger than + * allocated_size if attribute value is + * compressed or sparse. + */ int64_t initialized_size; int64_t compressed_size; } __attribute__((__packed__)) non_resident; |