[COVERITY] Check for NULL return from dict_lookup() in e2fsck

The dict_lookup() function can potentially return a NULL dnode_t.  It is
not checked in two places in the clone_file() function.  Looks to be
safe to continue if n is NULL, so just print a warning message and
continue.

Coverity ID: 9: Null Returns

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Brian Behlendorf 2007-03-19 08:52:10 -04:00 committed by Theodore Ts'o
parent d2021de5cf
commit 538e654c25
2 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,9 @@
2007-03-19 Theodore Tso <tytso@mit.edu> 2007-03-19 Theodore Tso <tytso@mit.edu>
* pass1b.c (clone_file): Fix a coverity-found bug; add error
checking in case dict_lookup() returns NULL when looking up
an block or inode record after cloning the EA block.
* profile.c (profile_init, get_dirlist): Fix bug where if a * profile.c (profile_init, get_dirlist): Fix bug where if a
profile directory is completely empty, the profile library profile directory is completely empty, the profile library
would segfault. would segfault.

View File

@ -752,11 +752,26 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
* them to point to the new EA block. * them to point to the new EA block.
*/ */
n = dict_lookup(&blk_dict, INT_TO_VOIDPTR(blk)); n = dict_lookup(&blk_dict, INT_TO_VOIDPTR(blk));
if (!n) {
com_err("clone_file", 0,
_("internal error: couldn't lookup EA "
"block record for %u"), blk);
retval = 0; /* OK to stumble on... */
goto errout;
}
db = (struct dup_block *) dnode_get(n); db = (struct dup_block *) dnode_get(n);
for (ino_el = db->inode_list; ino_el; ino_el = ino_el->next) { for (ino_el = db->inode_list; ino_el; ino_el = ino_el->next) {
if (ino_el->inode == ino) if (ino_el->inode == ino)
continue; continue;
n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino_el->inode)); n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino_el->inode));
if (!n) {
com_err("clone_file", 0,
_("internal error: couldn't lookup EA "
"inode record for %u"),
ino_el->inode);
retval = 0; /* OK to stumble on... */
goto errout;
}
di = (struct dup_inode *) dnode_get(n); di = (struct dup_inode *) dnode_get(n);
if (di->inode.i_file_acl == blk) { if (di->inode.i_file_acl == blk) {
di->inode.i_file_acl = dp->inode.i_file_acl; di->inode.i_file_acl = dp->inode.i_file_acl;