[Ocfs2-tools-devel] [PATCH] libocfs2: fix risk of using uninitialized variables

Joseph Qi joseph.qi at huawei.com
Tue Jul 12 06:26:57 PDT 2016


suballoc_bit in ocfs2_new_system_inode and p_blkno in
ocfs2_allocate_unwritten_extents may be used without initialized, so
fix them.

Signed-off-by: Joseph Qi <joseph.qi at huawei.com>
---
 libocfs2/alloc.c       | 3 ++-
 libocfs2/extend_file.c | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index 1cd21c6..258d4e5 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -306,7 +306,8 @@ errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino,
 						&gd_blkno, &suballoc_bit, ino);
 		if (ret)
 			goto out;
-	}
+	} else if (ret)
+		goto out;

 	memset(buf, 0, fs->fs_blocksize);
 	di = (struct ocfs2_dinode *)buf;
diff --git a/libocfs2/extend_file.c b/libocfs2/extend_file.c
index fbb770a..1038933 100644
--- a/libocfs2/extend_file.c
+++ b/libocfs2/extend_file.c
@@ -169,7 +169,7 @@ errcode_t ocfs2_allocate_unwritten_extents(ocfs2_filesys *fs, uint64_t ino,
 {
 	errcode_t ret = 0;
 	uint32_t n_clusters = 0, cpos;
-	uint64_t p_blkno, v_blkno, v_end, contig_blocks, wanted_blocks;
+	uint64_t p_blkno = 0, v_blkno, v_end, contig_blocks, wanted_blocks;
 	ocfs2_cached_inode *ci = NULL;

 	if (!(fs->fs_flags & OCFS2_FLAG_RW))
@@ -198,6 +198,9 @@ errcode_t ocfs2_allocate_unwritten_extents(ocfs2_filesys *fs, uint64_t ino,
 		ret = ocfs2_extent_map_get_blocks(ci, v_blkno, 1,
 						  &p_blkno, &contig_blocks,
 						  NULL);
+		if (ret)
+			continue;
+
 		if (p_blkno) {
 			v_blkno += contig_blocks;
 			continue;
-- 
1.8.4.3





More information about the Ocfs2-tools-devel mailing list