From: Brian Behlendorf Date: Mon, 19 Mar 2007 12:52:10 +0000 (-0400) Subject: [COVERITY] Check for NULL return from dict_lookup() in e2fsck X-Git-Tag: E2FSPROGS-1_40~110 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=538e654c25b7bc48d4dd86ebcc926585e530f0ef;p=thirdparty%2Fe2fsprogs.git [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 Signed-off-by: "Theodore Ts'o" --- diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index dd0524d49..0d530c008 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,5 +1,9 @@ 2007-03-19 Theodore Tso + * 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 directory is completely empty, the profile library would segfault. diff --git a/e2fsck/pass1b.c b/e2fsck/pass1b.c index cec60cf46..ae2b15a4d 100644 --- a/e2fsck/pass1b.c +++ b/e2fsck/pass1b.c @@ -752,11 +752,26 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino, * them to point to the new EA block. */ 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); for (ino_el = db->inode_list; ino_el; ino_el = ino_el->next) { if (ino_el->inode == ino) continue; 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); if (di->inode.i_file_acl == blk) { di->inode.i_file_acl = dp->inode.i_file_acl;