Skip to content

Commit

Permalink
Sanity check zap chunk index
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Behlendorf <[email protected]>
  • Loading branch information
behlendorf committed Feb 5, 2013
1 parent dd26aa5 commit faf8d51
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions module/zfs/zap_leaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,14 @@ zap_leaf_lookup_closest(zap_leaf_t *l,
for (lh = LEAF_HASH(l, h); lh <= bestlh; lh++) {
for (chunk = l->l_phys->l_hash[lh];
chunk != CHAIN_END; chunk = le->le_next) {
le = ZAP_LEAF_ENTRY(l, chunk);
/*
* Gracefully detect an incorrect chunk index before
* using it to deference a random memory address.
*/
if (chunk >= ZAP_LEAF_NUMCHUNKS(l))
return (EFAULT);

ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
le = ZAP_LEAF_ENTRY(l, chunk);
ASSERT3U(le->le_type, ==, ZAP_CHUNK_ENTRY);

if (HCD_GTEQ(le->le_hash, le->le_cd, h, cd) &&
Expand Down

0 comments on commit faf8d51

Please sign in to comment.