diff --git a/ChangeLog b/ChangeLog index b4a0f7674..ed44de64c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-09-22 Bean + + * fs/ntfs.c (grub_ntfs_iterate_dir): Fix a rare case where $BITMAP is + resident and in attribute list. + + * include/grub/ntfs.h (BMP_LEN): Removed. + 2008-09-22 Bean * disk/ata.c (grub_apapi_open): Initialize devfnd, no need to set diff --git a/fs/ntfs.c b/fs/ntfs.c index a590ade1e..e0e50f164 100644 --- a/fs/ntfs.c +++ b/fs/ntfs.c @@ -697,35 +697,32 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir, (u32at (cur_pos, ofs) == 0x490024) && (u32at (cur_pos, ofs + 4) == 0x300033)) { - if ((at->flags & AF_ALST) && (cur_pos[8] == 0)) - { - grub_error (GRUB_ERR_BAD_FS, - "$BITMAP should be non-resident when in attribute list"); - goto done; - } - if (cur_pos[8] == 0) - { - bitmap = (unsigned char *) (cur_pos + u16at (cur_pos, 0x14)); - bitmap_len = u32at (cur_pos, 0x10); - break; - } - if (u32at (cur_pos, 0x28) > BMP_LEN) - { - grub_error (GRUB_ERR_BAD_FS, "Non-resident $BITMAP too large"); - goto done; - } - bmp = grub_malloc (u32at (cur_pos, 0x28)); - if (bmp == NULL) - goto done; + int is_resident = (cur_pos[8] == 0); - bitmap = (unsigned char *) bmp; - bitmap_len = u32at (cur_pos, 0x30); - if (read_data (at, cur_pos, bmp, 0, u32at (cur_pos, 0x28), 0, 0)) + bitmap_len = ((is_resident) ? u32at (cur_pos, 0x10) : + (cur_pos, 0x28)); + + bmp = grub_malloc (bitmap_len); + if (bmp == NULL) + goto done; + + if (is_resident) { - grub_error (GRUB_ERR_BAD_FS, - "Fails to read non-resident $BITMAP"); - goto done; + grub_memcpy (bmp, (char *) (cur_pos + u16at (cur_pos, 0x14)), + bitmap_len); } + else + { + if (read_data (at, cur_pos, bmp, 0, bitmap_len, 0, 0)) + { + grub_error (GRUB_ERR_BAD_FS, + "Fails to read non-resident $BITMAP"); + goto done; + } + bitmap_len = u32at (cur_pos, 0x30); + } + + bitmap = (unsigned char *) bmp; break; } } diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h index bdd1a9ece..9b2ae0a0c 100644 --- a/include/grub/ntfs.h +++ b/include/grub/ntfs.h @@ -75,8 +75,6 @@ #define COM_LEN 4096 #define COM_SEC (COM_LEN >> BLK_SHR) -#define BMP_LEN 4096 - #define AF_ALST 1 #define AF_MMFT 2 #define AF_GPOS 4