[Ocfs2-tools-devel] [PATCH 2/6] fsck.ocfs2: Check the validity of variables before use
piaojun
piaojun at huawei.com
Wed Mar 25 23:50:06 PDT 2015
1. In o2fsck_icount_next_blkno(), we need check the value
ocfs2_bitmap_find_next_set() returns. Because if OCFS2_ET_INVALID_BIT is
returned, the value of 'start' must be illegal.
2. In mark_group_used(), we need check if 'desc' is null before use.
3. In o2fsck_verify_inode_fields(), we need check the value
o2fsck_add_dir_parent() returns. Because if it fails,
'ost->ost_dir_count++' should not be executed.
4. In walk_cwd(), 'de->inode ' should be initialized before use.
5. In o2fsck_check_refcount_clusters(), we need check the value
ocfs2_bitmap_test() returns. Because if OCFS2_ET_INVALID_BIT is
returned, we should end o2fsck_check_refcount_clusters() and return the
error number to its caller.
Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>
---
fsck.ocfs2/icount.c | 3 ++-
fsck.ocfs2/pass0.c | 2 ++
fsck.ocfs2/pass1.c | 6 ++++--
fsck.ocfs2/pass1b.c | 1 +
fsck.ocfs2/refcount.c | 8 +++++++-
5 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/fsck.ocfs2/icount.c b/fsck.ocfs2/icount.c
index 1fa7aab..9813aaf 100644
--- a/fsck.ocfs2/icount.c
+++ b/fsck.ocfs2/icount.c
@@ -207,7 +207,8 @@ errcode_t o2fsck_icount_next_blkno(o2fsck_icount *icount, uint64_t start,
ret = ocfs2_bitmap_find_next_set(icount->ic_single_bm, start,
&next_bit);
-
+ if (OCFS2_ET_INVALID_BIT == ret)
+ return ret;
in = icount_search(icount, start, &next);
if (in == NULL)
in = next;
diff --git a/fsck.ocfs2/pass0.c b/fsck.ocfs2/pass0.c
index fd1848b..8e38c9e 100644
--- a/fsck.ocfs2/pass0.c
+++ b/fsck.ocfs2/pass0.c
@@ -595,6 +595,8 @@ static void mark_group_used(o2fsck_state *ost, struct chain_state *cs,
return;
}
+ if (!desc)
+ return;
/* Now check the discontiguous group case. */
for (i = 0; i < desc->bg_list.l_next_free_rec; i++) {
struct ocfs2_extent_rec *rec = &desc->bg_list.l_recs[i];
diff --git a/fsck.ocfs2/pass1.c b/fsck.ocfs2/pass1.c
index c076e28..5fa8202 100644
--- a/fsck.ocfs2/pass1.c
+++ b/fsck.ocfs2/pass1.c
@@ -439,7 +439,7 @@ static void o2fsck_verify_inode_fields(ocfs2_filesys *fs,
{
int clear = 0;
int depth;
-
+ errcode_t ret;
verbosef("checking inode %"PRIu64"'s fields\n", blkno);
if (di->i_fs_generation != ost->ost_fs_generation) {
@@ -537,8 +537,10 @@ static void o2fsck_verify_inode_fields(ocfs2_filesys *fs,
if (S_ISDIR(di->i_mode)) {
o2fsck_bitmap_set(ost->ost_dir_inodes, blkno, NULL);
- o2fsck_add_dir_parent(&ost->ost_dir_parents, blkno, 0, 0,
+ ret = o2fsck_add_dir_parent(&ost->ost_dir_parents, blkno, 0, 0,
di->i_flags & OCFS2_ORPHANED_FL);
+ if (ret)
+ goto out;
ost->ost_dir_count++;
if (di->i_dyn_features & OCFS2_INLINE_DATA_FL)
ost->ost_inline_dir_count++;
diff --git a/fsck.ocfs2/pass1b.c b/fsck.ocfs2/pass1b.c
index e3ee739..21bdcd7 100644
--- a/fsck.ocfs2/pass1b.c
+++ b/fsck.ocfs2/pass1b.c
@@ -972,6 +972,7 @@ static void walk_cwd(struct dir_scan_context *scan)
memcpy(de->name, scan->ds_cwd, scan->ds_cwdlen);
de->name_len = scan->ds_cwdlen;
+ de->inode = scan->ds_ino;
name_inode(scan, de);
free(de);
diff --git a/fsck.ocfs2/refcount.c b/fsck.ocfs2/refcount.c
index edb2cea..7d83b69 100644
--- a/fsck.ocfs2/refcount.c
+++ b/fsck.ocfs2/refcount.c
@@ -909,9 +909,15 @@ static errcode_t o2fsck_check_refcount_clusters(o2fsck_state *ost,
p_cend = start;
clusters = len;
while (clusters) {
- ocfs2_bitmap_test(
+ ret = ocfs2_bitmap_test(
ost->ost_duplicate_clusters,
p_cend, &val);
+ if (ret) {
+ com_err(whoami, ret, "while testing cluster %"PRIu64" in "
+ "the duplicate cluster map", p_cend);
+ goto out;
+ }
+
if (val)
break;
--
1.8.4.3
More information about the Ocfs2-tools-devel
mailing list