From a4b66fb1339c1f60c2d280dd949754d4206aca0a Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 19 Mar 2007 08:58:47 -0400 Subject: [PATCH] [COVERITY] Add missing NULL check to e2fsck_get_dir_info() 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 Signed-off-by: "Theodore Ts'o" --- e2fsck/ChangeLog | 6 ++++++ e2fsck/pass3.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 0d530c0..4e0ba88 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,5 +1,11 @@ 2007-03-19 Theodore Tso + * 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. diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c index 66ffc46..26c0a03 100644 --- a/e2fsck/pass3.c +++ b/e2fsck/pass3.c @@ -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; } -- 1.8.3.1