Andy Alex
2014-Jun-02 17:28 UTC
[syslinux] [PATCH] NTFS: fix incorrect file->offset usage in ntfs_readdir
file->offset is used to store position in index root between ntfs_readdir calls. Previously, pointer to buffer was stored in this field. However this buffer is reallocated and read each ntfs_readdir call so the pointer may become incorrect. Now offset in index root rather than pointer is stored in this field. Signed-off-by: Andy Alex <andy at r-tt.com> --- diff -uprN syslinux-6.03-pre12.orig/core/fs/ntfs/ntfs.c syslinux-6.03-pre12/core/fs/ntfs/ntfs.c --- syslinux-6.03-pre12.orig/core/fs/ntfs/ntfs.c 2014-05-26 20:30:30.000000000 -0400 +++ syslinux-6.03-pre12/core/fs/ntfs/ntfs.c 2014-06-02 13:16:03.000000000 -0400 @@ -1058,14 +1058,13 @@ static int ntfs_readdir(struct file *fil attr->data.resident.value_offset); if (!file->offset && readdir_state->in_idx_root) { - file->offset = (uint32_t)((uint8_t *)&ir->index + - ir->index.entries_offset); + file->offset = ir->index.entries_offset; } idx_root_next_entry: if (readdir_state->in_idx_root) { - ie = (struct ntfs_idx_entry *)(uint8_t *)file->offset; - if (ie->flags & INDEX_ENTRY_END) { + ie = (struct ntfs_idx_entry *)((uint8_t *)&ir->index + file->offset); + if (ie->flags & INDEX_ENTRY_END) { file->offset = 0; readdir_state->in_idx_root = false; readdir_state->idx_blks_count = 1; @@ -1074,7 +1073,7 @@ idx_root_next_entry: goto descend_into_child_node; } - file->offset = (uint32_t)((uint8_t *)ie + ie->len); + file->offset += ie->len; len = ntfs_cvt_filename(filename, ie); if (!is_filename_printable(filename)) goto idx_root_next_entry;
Andy Alex
2014-Jun-02 17:28 UTC
[syslinux] [PATCH] NTFS: fix incorrect file->offset usage in ntfs_readdir
file->offset is used to store position in index root between ntfs_readdir calls. Previously, pointer to buffer was stored in this field. However this buffer is reallocated and read each ntfs_readdir call so the pointer may become incorrect. Now offset in index root rather than pointer is stored in this field. Signed-off-by: Andy Alex <andy at r-tt.com> --- diff -uprN syslinux-6.03-pre12.orig/core/fs/ntfs/ntfs.c syslinux-6.03-pre12/core/fs/ntfs/ntfs.c --- syslinux-6.03-pre12.orig/core/fs/ntfs/ntfs.c 2014-05-26 20:30:30.000000000 -0400 +++ syslinux-6.03-pre12/core/fs/ntfs/ntfs.c 2014-06-02 13:16:03.000000000 -0400 @@ -1058,14 +1058,13 @@ static int ntfs_readdir(struct file *fil attr->data.resident.value_offset); if (!file->offset && readdir_state->in_idx_root) { - file->offset = (uint32_t)((uint8_t *)&ir->index + - ir->index.entries_offset); + file->offset = ir->index.entries_offset; } idx_root_next_entry: if (readdir_state->in_idx_root) { - ie = (struct ntfs_idx_entry *)(uint8_t *)file->offset; - if (ie->flags & INDEX_ENTRY_END) { + ie = (struct ntfs_idx_entry *)((uint8_t *)&ir->index + file->offset); + if (ie->flags & INDEX_ENTRY_END) { file->offset = 0; readdir_state->in_idx_root = false; readdir_state->idx_blks_count = 1; @@ -1074,7 +1073,7 @@ idx_root_next_entry: goto descend_into_child_node; } - file->offset = (uint32_t)((uint8_t *)ie + ie->len); + file->offset += ie->len; len = ntfs_cvt_filename(filename, ie); if (!is_filename_printable(filename)) goto idx_root_next_entry;
H. Peter Anvin
2014-Jun-02 20:54 UTC
[syslinux] [PATCH] NTFS: fix incorrect file->offset usage in ntfs_readdir
On 06/02/2014 10:28 AM, Andy Alex wrote:> file->offset is used to store position in index root between > ntfs_readdir calls. > Previously, pointer to buffer was stored in this field. However this > buffer is reallocated and read each ntfs_readdir call so the pointer may > become incorrect. > Now offset in index root rather than pointer is stored in this field. > > Signed-off-by: Andy Alex <andy at r-tt.com>I applied this patch manually, and it seems to work. Thank you! -hpa