Commit 55581d01 authored by Eric Sandeen's avatar Eric Sandeen Committed by Linus Torvalds

address hfs on-disk corruption robustness review comments

Address Roman's review comments for the previously sent on-disk
corruption hfs robustness patch.

- use 0 as a failure value, rather than making a new macro HFS_BAD_KEYLEN,
  and use a switch statement instead of if's.

- Add new fail: target to __hfs_brec_find to skip assignments using bad
  values when exiting with a failure.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: default avatarEric Sandeen <sandeen@redhat.com>
Cc: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7c28cbae
...@@ -52,9 +52,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -52,9 +52,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
rec = (e + b) / 2; rec = (e + b) / 2;
len = hfs_brec_lenoff(bnode, rec, &off); len = hfs_brec_lenoff(bnode, rec, &off);
keylen = hfs_brec_keylen(bnode, rec); keylen = hfs_brec_keylen(bnode, rec);
if (keylen == HFS_BAD_KEYLEN) { if (keylen == 0) {
res = -EINVAL; res = -EINVAL;
goto done; goto fail;
} }
hfs_bnode_read(bnode, fd->key, off, keylen); hfs_bnode_read(bnode, fd->key, off, keylen);
cmpval = bnode->tree->keycmp(fd->key, fd->search_key); cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
...@@ -71,9 +71,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -71,9 +71,9 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
if (rec != e && e >= 0) { if (rec != e && e >= 0) {
len = hfs_brec_lenoff(bnode, e, &off); len = hfs_brec_lenoff(bnode, e, &off);
keylen = hfs_brec_keylen(bnode, e); keylen = hfs_brec_keylen(bnode, e);
if (keylen == HFS_BAD_KEYLEN) { if (keylen == 0) {
res = -EINVAL; res = -EINVAL;
goto done; goto fail;
} }
hfs_bnode_read(bnode, fd->key, off, keylen); hfs_bnode_read(bnode, fd->key, off, keylen);
} }
...@@ -83,6 +83,7 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd) ...@@ -83,6 +83,7 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
fd->keylength = keylen; fd->keylength = keylen;
fd->entryoffset = off + keylen; fd->entryoffset = off + keylen;
fd->entrylength = len - keylen; fd->entrylength = len - keylen;
fail:
return res; return res;
} }
...@@ -206,7 +207,7 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt) ...@@ -206,7 +207,7 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt)
len = hfs_brec_lenoff(bnode, fd->record, &off); len = hfs_brec_lenoff(bnode, fd->record, &off);
keylen = hfs_brec_keylen(bnode, fd->record); keylen = hfs_brec_keylen(bnode, fd->record);
if (keylen == HFS_BAD_KEYLEN) { if (keylen == 0) {
res = -EINVAL; res = -EINVAL;
goto out; goto out;
} }
......
...@@ -49,14 +49,14 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec) ...@@ -49,14 +49,14 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
if (retval > node->tree->max_key_len + 2) { if (retval > node->tree->max_key_len + 2) {
printk(KERN_ERR "hfs: keylen %d too large\n", printk(KERN_ERR "hfs: keylen %d too large\n",
retval); retval);
retval = HFS_BAD_KEYLEN; retval = 0;
} }
} else { } else {
retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1; retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1;
if (retval > node->tree->max_key_len + 1) { if (retval > node->tree->max_key_len + 1) {
printk(KERN_ERR "hfs: keylen %d too large\n", printk(KERN_ERR "hfs: keylen %d too large\n",
retval); retval);
retval = HFS_BAD_KEYLEN; retval = 0;
} }
} }
} }
......
...@@ -81,16 +81,24 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke ...@@ -81,16 +81,24 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
goto fail_page; goto fail_page;
if (!tree->node_count) if (!tree->node_count)
goto fail_page; goto fail_page;
if ((id == HFS_EXT_CNID) && (tree->max_key_len != HFS_MAX_EXT_KEYLEN)) { switch (id) {
case HFS_EXT_CNID:
if (tree->max_key_len != HFS_MAX_EXT_KEYLEN) {
printk(KERN_ERR "hfs: invalid extent max_key_len %d\n", printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
tree->max_key_len); tree->max_key_len);
goto fail_page; goto fail_page;
} }
if ((id == HFS_CAT_CNID) && (tree->max_key_len != HFS_MAX_CAT_KEYLEN)) { break;
case HFS_CAT_CNID:
if (tree->max_key_len != HFS_MAX_CAT_KEYLEN) {
printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n", printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
tree->max_key_len); tree->max_key_len);
goto fail_page; goto fail_page;
} }
break;
default:
BUG();
}
tree->node_size_shift = ffs(size) - 1; tree->node_size_shift = ffs(size) - 1;
tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
......
...@@ -28,8 +28,6 @@ ...@@ -28,8 +28,6 @@
#define HFS_MAX_NAMELEN 128 #define HFS_MAX_NAMELEN 128
#define HFS_MAX_VALENCE 32767U #define HFS_MAX_VALENCE 32767U
#define HFS_BAD_KEYLEN 0xFF
/* Meanings of the drAtrb field of the MDB, /* Meanings of the drAtrb field of the MDB,
* Reference: _Inside Macintosh: Files_ p. 2-61 * Reference: _Inside Macintosh: Files_ p. 2-61
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment