2007-02-10 02:14:51

by Brian Behlendorf

[permalink] [raw]
Subject: e2fsprogs coverity patch <cid-9.diff>

Lawrence Livermore National Labs recently ran the source code
analysis tool Coverity over the e2fsprogs-1.39 source to see
if it would identify any significant bugs. The analysis
turned up 38 mostly minor issues which are enumerated here
with patches. We went through and resolved these issues
but would love to see these mostly minor changes reviewed
and commited upstream.

Thanks,
Brian Behlendorf <[email protected]>, and
Herb Wartens <[email protected]>

-----------------------------------------------------------------------------
Coverity ID: 9: Null Returns

dict_lookup() can potentially return a NULL dnode_t. It is not
checked in two places in the clone_file() function. Looks to be
safe to check if n is not NULL. If n is NULL then point out the
error.

Index: e2fsprogs+chaos/e2fsck/pass1b.c
===================================================================
--- e2fsprogs+chaos.orig/e2fsck/pass1b.c
+++ e2fsprogs+chaos/e2fsck/pass1b.c
@@ -752,19 +752,33 @@ static int clone_file(e2fsck_t ctx, ext2
* them to point to the new EA block.
*/
n = dict_lookup(&blk_dict, INT_TO_VOIDPTR(blk));
- 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));
- di = (struct dup_inode *) dnode_get(n);
- if (di->inode.i_file_acl == blk) {
- di->inode.i_file_acl = dp->inode.i_file_acl;
- e2fsck_write_inode(ctx, ino_el->inode,
- &di->inode, "clone file EA");
- decrement_badcount(ctx, blk, db);
+ if (n) {
+ 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) {
+ di = (struct dup_inode *) dnode_get(n);
+ if (di->inode.i_file_acl == blk) {
+ di->inode.i_file_acl = dp->inode.i_file_acl;
+ e2fsck_write_inode(ctx, ino_el->inode,
+ &di->inode, "clone file EA");
+ decrement_badcount(ctx, blk, db);
+ }
+ }
+ else {
+ com_err("clone_file", 0,
+ _("internal error; can't find dup_blk for %u\n"),
+ ino_el->inode);
+ }
}
}
+ else {
+ com_err("clone_file", 0,
+ _("internal error; can't find dup_blk for %u\n"),
+ blk);
+ }
}
retval = 0;
errout: