@@ -113,6 +113,8 @@ void do_get_xattr(int argc, char **argv)
while ((i = getopt(argc, argv, "f:")) != -1) {
switch (i) {
case 'f':
+ if (fp)
+ fclose(fp);
fp = fopen(optarg, "w");
if (fp == NULL) {
perror(optarg);
@@ -182,6 +184,8 @@ void do_set_xattr(int argc, char **argv)
while ((i = getopt(argc, argv, "f:")) != -1) {
switch (i) {
case 'f':
+ if (fp)
+ fclose(fp);
fp = fopen(optarg, "r");
if (fp == NULL) {
perror(optarg);
@@ -2013,8 +2013,12 @@ fix_problem_now:
pctx->blk2 = extent.e_lblk;
pctx->num = e_info.curr_level - 1;
problem = PR_1_EXTENT_INDEX_START_INVALID;
- if (fix_problem(ctx, problem, pctx))
- ext2fs_extent_fix_parents(ehandle);
+ if (fix_problem(ctx, problem, pctx)) {
+ pctx->errcode =
+ ext2fs_extent_fix_parents(ehandle);
+ if (pctx->errcode)
+ return;
+ }
}
scan_extent_node(ctx, pctx, pb, extent.e_lblk,
last_lblk, eof_block, ehandle);
@@ -570,7 +570,9 @@ void check_super_block(e2fsck_t ctx)
return;
}
- should_be = sb->s_inodes_per_group * fs->group_desc_count;
+ should_be = (blk64_t)sb->s_inodes_per_group * fs->group_desc_count;
+ if (should_be > UINT_MAX)
+ should_be = UINT_MAX;
if (sb->s_inodes_count != should_be) {
pctx.ino = sb->s_inodes_count;
pctx.ino2 = should_be;
@@ -402,8 +402,12 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino,
goto errout;
retval = 0;
- /* Jump forward to the next extent. */
- (void) ext2fs_extent_goto(handle, next_lblk);
+ /*
+ * Jump forward to the next extent. If there are
+ * errors, the ext2fs_extent_get down below will
+ * capture them for us.
+ */
+ (void)ext2fs_extent_goto(handle, next_lblk);
op = EXT2_EXTENT_CURRENT;
}
if (retval)
@@ -117,9 +117,9 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
case S_IFSOCK:
mode = LINUX_S_IFSOCK;
filetype = EXT2_FT_SOCK;
+ break;
default:
- abort();
- /* NOTREACHED */
+ return EXT2_ET_INVALID_ARGUMENT;
}
if (!(fs->flags & EXT2_FLAG_RW)) {
@@ -146,7 +146,7 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
}
if (retval) {
com_err(name, retval, 0);
- return -1;
+ return retval;
}
if (ext2fs_test_inode_bitmap2(fs->inode_map, ino))
com_err(__func__, 0, "Warning: inode already set");
@@ -354,7 +354,7 @@ errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd, const char *src,
int bufsize = IO_BUFSIZE;
int make_holes = 0;
- fd = open(src, O_RDONLY);
+ fd = ext2fs_open_file(src, O_RDONLY, 0);
if (fd < 0) {
com_err(src, errno, 0);
return errno;
@@ -535,7 +535,8 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
com_err(__func__, errno,
_("while trying to readlink \"%s\""),
name);
- return errno;
+ retval = errno;
+ goto out;
}
ln_target[read_cnt] = '\0';
retval = do_symlink_internal(fs, parent_ino, name,
Fix various small resource leaks and error code handling issues that Coverity pointed out. Fixes-Coverity-Bugs: 1215250, 1193379, 119194[2-4], 1049160 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> --- debugfs/xattrs.c | 4 ++++ e2fsck/pass1.c | 8 ++++++-- e2fsck/super.c | 4 +++- lib/ext2fs/punch.c | 8 ++++++-- misc/create_inode.c | 11 ++++++----- 5 files changed, 25 insertions(+), 10 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html