Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 75309
b: refs/heads/master
c: cf05946
h: refs/heads/master
i:
  75307: c1def75
v: v3
  • Loading branch information
Eric Sandeen authored and Linus Torvalds committed Jan 9, 2008
1 parent 046648a commit 7fa47a1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 467bc461d2845f6a04b124bca1ae6ecc554e1ee5
refs/heads/master: cf0594625083111ae522496dc1c256f7476939c2
12 changes: 12 additions & 0 deletions trunk/fs/hfs/bfind.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
rec = (e + b) / 2;
len = hfs_brec_lenoff(bnode, rec, &off);
keylen = hfs_brec_keylen(bnode, rec);
if (keylen == HFS_BAD_KEYLEN) {
res = -EINVAL;
goto done;
}
hfs_bnode_read(bnode, fd->key, off, keylen);
cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
if (!cmpval) {
Expand All @@ -67,6 +71,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
if (rec != e && e >= 0) {
len = hfs_brec_lenoff(bnode, e, &off);
keylen = hfs_brec_keylen(bnode, e);
if (keylen == HFS_BAD_KEYLEN) {
res = -EINVAL;
goto done;
}
hfs_bnode_read(bnode, fd->key, off, keylen);
}
done:
Expand Down Expand Up @@ -198,6 +206,10 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt)

len = hfs_brec_lenoff(bnode, fd->record, &off);
keylen = hfs_brec_keylen(bnode, fd->record);
if (keylen == HFS_BAD_KEYLEN) {
res = -EINVAL;
goto out;
}
fd->keyoffset = off;
fd->keylength = keylen;
fd->entryoffset = off + keylen;
Expand Down
15 changes: 13 additions & 2 deletions trunk/fs/hfs/brec.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,21 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
recoff = hfs_bnode_read_u16(node, node->tree->node_size - (rec + 1) * 2);
if (!recoff)
return 0;
if (node->tree->attributes & HFS_TREE_BIGKEYS)
if (node->tree->attributes & HFS_TREE_BIGKEYS) {
retval = hfs_bnode_read_u16(node, recoff) + 2;
else
if (retval > node->tree->max_key_len + 2) {
printk(KERN_ERR "hfs: keylen %d too large\n",
retval);
retval = HFS_BAD_KEYLEN;
}
} else {
retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1;
if (retval > node->tree->max_key_len + 1) {
printk(KERN_ERR "hfs: keylen %d too large\n",
retval);
retval = HFS_BAD_KEYLEN;
}
}
}
return retval;
}
Expand Down
13 changes: 12 additions & 1 deletion trunk/fs/hfs/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
goto fail_page;
if (!tree->node_count)
goto fail_page;
if ((id == HFS_EXT_CNID) && (tree->max_key_len != HFS_MAX_EXT_KEYLEN)) {
printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
tree->max_key_len);
goto fail_page;
}
if ((id == HFS_CAT_CNID) && (tree->max_key_len != HFS_MAX_CAT_KEYLEN)) {
printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
tree->max_key_len);
goto fail_page;
}

tree->node_size_shift = ffs(size) - 1;
tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;

Expand All @@ -89,9 +100,9 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
return tree;

fail_page:
tree->inode->i_mapping->a_ops = &hfs_aops;
page_cache_release(page);
free_tree:
tree->inode->i_mapping->a_ops = &hfs_aops;
iput(tree->inode);
kfree(tree);
return NULL;
Expand Down
5 changes: 5 additions & 0 deletions trunk/fs/hfs/hfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define HFS_MAX_NAMELEN 128
#define HFS_MAX_VALENCE 32767U

#define HFS_BAD_KEYLEN 0xFF

/* Meanings of the drAtrb field of the MDB,
* Reference: _Inside Macintosh: Files_ p. 2-61
*/
Expand Down Expand Up @@ -167,6 +169,9 @@ typedef union hfs_btree_key {
struct hfs_ext_key ext;
} hfs_btree_key;

#define HFS_MAX_CAT_KEYLEN (sizeof(struct hfs_cat_key) - sizeof(u8))
#define HFS_MAX_EXT_KEYLEN (sizeof(struct hfs_ext_key) - sizeof(u8))

typedef union hfs_btree_key btree_key;

struct hfs_extent {
Expand Down

0 comments on commit 7fa47a1

Please sign in to comment.