Skip to content

Commit c62663a

Browse files
committed
hfs: make proper initalization of struct hfs_find_data
Potenatially, __hfs_ext_read_extent() could operate by not initialized values of fd->key after hfs_brec_find() call: static inline int __hfs_ext_read_extent(struct hfs_find_data *fd, struct hfs_extent *extent, u32 cnid, u32 block, u8 type) { int res; hfs_ext_build_key(fd->search_key, cnid, block, type); fd->key->ext.FNum = 0; res = hfs_brec_find(fd); if (res && res != -ENOENT) return res; if (fd->key->ext.FNum != fd->search_key->ext.FNum || fd->key->ext.FkType != fd->search_key->ext.FkType) return -ENOENT; if (fd->entrylength != sizeof(hfs_extent_rec)) return -EIO; hfs_bnode_read(fd->bnode, extent, fd->entryoffset, sizeof(hfs_extent_rec)); return 0; } This patch changes kmalloc() on kzalloc() in hfs_find_init() and intializes fd->record, fd->keyoffset, fd->keylength, fd->entryoffset, fd->entrylength for the case if hfs_brec_find() has been found nothing in the b-tree node. Signed-off-by: Viacheslav Dubeyko <[email protected]> cc: John Paul Adrian Glaubitz <[email protected]> cc: Yangtao Li <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Viacheslav Dubeyko <[email protected]>
1 parent 4840cea commit c62663a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/hfs/bfind.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)
2121

2222
fd->tree = tree;
2323
fd->bnode = NULL;
24-
ptr = kmalloc(tree->max_key_len * 2 + 4, GFP_KERNEL);
24+
ptr = kzalloc(tree->max_key_len * 2 + 4, GFP_KERNEL);
2525
if (!ptr)
2626
return -ENOMEM;
2727
fd->search_key = ptr;
@@ -115,6 +115,12 @@ int hfs_brec_find(struct hfs_find_data *fd)
115115
__be32 data;
116116
int height, res;
117117

118+
fd->record = -1;
119+
fd->keyoffset = -1;
120+
fd->keylength = -1;
121+
fd->entryoffset = -1;
122+
fd->entrylength = -1;
123+
118124
tree = fd->tree;
119125
if (fd->bnode)
120126
hfs_bnode_put(fd->bnode);

0 commit comments

Comments
 (0)