Whamcloud - gitweb
[COVERITY] Add missing NULL check to e2fsck_get_dir_info()
authorBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 19 Mar 2007 12:58:47 +0000 (08:58 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 19 Mar 2007 12:58:47 +0000 (08:58 -0400)
It is possible that e2fsck_get_dir_info() returns a NULL pointer.
We do not want to blow up when dereferencing p.  It seems to be
more sane/safe to call fix_problem(ctx, PR_3_NO_DIRINFO, pctx)
if p is NULL at this point since we do not have any DIRINFO
for pctx->ino.

Also fix another (already existing) error check for
e2fsck_get_dir_info() later in the function so that it reports the
correct inode number if the dirinfo information is not found for
p->parent.

(Both of these are "should-never-happen" internal e2fsck errors that
would indicate a programming bug of some kind.)

Coverity ID: 10: Null Returns

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/ChangeLog
e2fsck/pass3.c

index 0d530c0..4e0ba88 100644 (file)
@@ -1,5 +1,11 @@
 2007-03-19  Theodore Tso  <tytso@mit.edu>
 
+       * pass3.c (check_directory): Add error check in case
+               e2fsck_get_dir_info() returns NULL.  Also fix another
+               error check for e2fsck_get_dir_info() to display the
+               correct inode number in case of this internal (should
+               never happen) error.
+
        * 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.
index 66ffc46..26c0a03 100644 (file)
@@ -306,6 +306,11 @@ static int check_directory(e2fsck_t ctx, struct dir_info *dir,
                                        ext2fs_unmark_valid(fs);
                                else {
                                        p = e2fsck_get_dir_info(ctx, pctx->ino);
+                                       if (!p) {
+                                               fix_problem(ctx, 
+                                                   PR_3_NO_DIRINFO, pctx);
+                                               return 0;
+                                       }
                                        p->parent = ctx->lost_and_found;
                                        fix_dotdot(ctx, p, ctx->lost_and_found);
                                }
@@ -314,6 +319,7 @@ static int check_directory(e2fsck_t ctx, struct dir_info *dir,
                }
                p = e2fsck_get_dir_info(ctx, p->parent);
                if (!p) {
+                       pctx->ino = p->parent;
                        fix_problem(ctx, PR_3_NO_DIRINFO, pctx);
                        return 0;
                }