[syslinux:master] ntfs: handle offsets when walking through attribute list's entries

syslinux-bot for Paulo Alcantara pcacjr at gmail.com
Fri Feb 24 10:45:14 PST 2012


Commit-ID:  77f467ca6a200e64a13c23bf38e7513b80b811de
Gitweb:     http://www.syslinux.org/commit/77f467ca6a200e64a13c23bf38e7513b80b811de
Author:     Paulo Alcantara <pcacjr at gmail.com>
AuthorDate: Wed, 18 Jan 2012 21:18:25 -0300
Committer:  Paulo Alcantara <pcacjr at gmail.com>
CommitDate: Sat, 11 Feb 2012 16:06:07 -0300

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 at gmail.com>

---
 core/fs/ntfs/ntfs.c |   33 ++++++++++++++++-----------------
 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 f64c8c8..c51f1f9 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 8a885b6..3f2b260 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;


More information about the Syslinux-commits mailing list