linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, darrick.wong@oracle.com
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 01/14] misc: fix Coverity bugs
Date: Wed, 13 May 2015 17:21:15 -0700	[thread overview]
Message-ID: <20150514002114.10785.41768.stgit@birch.djwong.org> (raw)
In-Reply-To: <20150514002108.10785.85860.stgit@birch.djwong.org>

Fix Coverity bugs 1297093,1297096, 1297489, 1297491, 1297493, 1297506,
1297507, 1297514, 1297516, and 1297517.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 debugfs/util.c     |    2 +-
 e2fsck/extents.c   |   12 +++++++++---
 e2fsck/readahead.c |    2 +-
 e2fsck/unix.c      |    4 ++++
 lib/e2p/feature.c  |    4 ++--
 lib/e2p/mntopts.c  |    2 +-
 misc/e4defrag.c    |    4 +++-
 misc/logsave.c     |    2 +-
 8 files changed, 22 insertions(+), 10 deletions(-)


diff --git a/debugfs/util.c b/debugfs/util.c
index af14539..4fef89a 100644
--- a/debugfs/util.c
+++ b/debugfs/util.c
@@ -390,7 +390,7 @@ int common_block_args_process(int argc, char *argv[],
 		return 1;
 	if (*block == 0) {
 		com_err(argv[0], 0, "Invalid block number 0");
-		err = 1;
+		return 1;
 	}
 
 	if (argc > 2) {
diff --git a/e2fsck/extents.c b/e2fsck/extents.c
index a08fa94..407dafb 100644
--- a/e2fsck/extents.c
+++ b/e2fsck/extents.c
@@ -27,6 +27,8 @@ static errcode_t e2fsck_rebuild_extents(e2fsck_t ctx, ext2_ino_t ino);
 /* Schedule an inode to have its extent tree rebuilt during pass 1E. */
 errcode_t e2fsck_rebuild_extents_later(e2fsck_t ctx, ext2_ino_t ino)
 {
+	errcode_t retval = 0;
+
 	if (!EXT2_HAS_INCOMPAT_FEATURE(ctx->fs->super,
 				       EXT3_FEATURE_INCOMPAT_EXTENTS) ||
 	    (ctx->options & E2F_OPT_NO) ||
@@ -37,13 +39,15 @@ errcode_t e2fsck_rebuild_extents_later(e2fsck_t ctx, ext2_ino_t ino)
 		return e2fsck_rebuild_extents(ctx, ino);
 
 	if (!ctx->inodes_to_rebuild)
-		e2fsck_allocate_inode_bitmap(ctx->fs,
+		retval = e2fsck_allocate_inode_bitmap(ctx->fs,
 					     _("extent rebuild inode map"),
 					     EXT2FS_BMAP64_RBTREE,
 					     "inodes_to_rebuild",
 					     &ctx->inodes_to_rebuild);
-	if (ctx->inodes_to_rebuild)
-		ext2fs_mark_inode_bitmap2(ctx->inodes_to_rebuild, ino);
+	if (retval)
+		return retval;
+
+	ext2fs_mark_inode_bitmap2(ctx->inodes_to_rebuild, ino);
 	return 0;
 }
 
@@ -225,6 +229,8 @@ static errcode_t rebuild_extent_tree(e2fsck_t ctx, struct extent_list *list,
 	/* Collect lblk->pblk mappings */
 	if (inode.i_flags & EXT4_EXTENTS_FL) {
 		retval = load_extents(ctx, list);
+		if (retval)
+			goto err;
 		goto extents_loaded;
 	}
 
diff --git a/e2fsck/readahead.c b/e2fsck/readahead.c
index 4429a37..a860f2b 100644
--- a/e2fsck/readahead.c
+++ b/e2fsck/readahead.c
@@ -242,7 +242,7 @@ unsigned long long e2fsck_guess_readahead(ext2_filsys fs)
 	 * worth of inode table blocks seems to yield the largest reductions
 	 * in e2fsck runtime.
 	 */
-	guess = 2 * fs->blocksize * fs->inode_blocks_per_group;
+	guess = 2ULL * fs->blocksize * fs->inode_blocks_per_group;
 
 	/* Disable RA if it'd use more 1/50th of RAM. */
 	if (get_memory_size() > (guess * 50))
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index 4bad553..940ecb4 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -682,6 +682,10 @@ static void parse_extended_opts(e2fsck_t ctx, const char *opts)
 			}
 			ctx->ext_attr_ver = ea_ver;
 		} else if (strcmp(token, "readahead_kb") == 0) {
+			if (!arg) {
+				extended_usage++;
+				continue;
+			}
 			reada_kb = strtoull(arg, &p, 0);
 			if (*p) {
 				fprintf(stderr, "%s",
diff --git a/lib/e2p/feature.c b/lib/e2p/feature.c
index 73884f2..d1d4762 100644
--- a/lib/e2p/feature.c
+++ b/lib/e2p/feature.c
@@ -187,7 +187,7 @@ int e2p_string2feature(char *string, int *compat_type, unsigned int *mask)
 	if (string[9] == 0)
 		return 1;
 	num = strtol(string+9, &eptr, 10);
-	if (num > 32 || num < 0)
+	if (num > 31 || num < 0)
 		return 1;
 	if (*eptr)
 		return 1;
@@ -261,7 +261,7 @@ int e2p_jrnl_string2feature(char *string, int *compat_type, unsigned int *mask)
 	if (string[9] == 0)
 		return 1;
 	num = strtol(string+9, &eptr, 10);
-	if (num > 32 || num < 0)
+	if (num > 31 || num < 0)
 		return 1;
 	if (*eptr)
 		return 1;
diff --git a/lib/e2p/mntopts.c b/lib/e2p/mntopts.c
index d56cc52..ff2e5de 100644
--- a/lib/e2p/mntopts.c
+++ b/lib/e2p/mntopts.c
@@ -72,7 +72,7 @@ int e2p_string2mntopt(char *string, unsigned int *mask)
 	if (string[8] == 0)
 		return 1;
 	num = strtol(string+8, &eptr, 10);
-	if (num > 32 || num < 0)
+	if (num > 31 || num < 0)
 		return 1;
 	if (*eptr)
 		return 1;
diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index d0eac60..3f949d0 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -387,8 +387,10 @@ static int page_in_core(int fd, struct move_extent defrag_data,
 	*page_num = 0;
 	*page_num = (length + pagesize - 1) / pagesize;
 	*vec = (unsigned char *)calloc(*page_num, 1);
-	if (*vec == NULL)
+	if (*vec == NULL) {
+		munmap(page, length);
 		return -1;
+	}
 
 	/* Get information on whether pages are in core */
 	if (mincore(page, (size_t)length, *vec) == -1 ||
diff --git a/misc/logsave.c b/misc/logsave.c
index f6cc42a..6a624de 100644
--- a/misc/logsave.c
+++ b/misc/logsave.c
@@ -219,7 +219,7 @@ static int run_program(char **argv)
 			sprintf(buffer, "died with signal %d\n",
 				WTERMSIG(status));
 			send_output(buffer, 0, SEND_BOTH);
-			rc = 1;
+			return 1;
 		}
 		rc = 0;
 	}


  reply	other threads:[~2015-05-14  0:21 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-14  0:21 [PATCH 00/14] e2fsprogs May 2015 patchbomb Darrick J. Wong
2015-05-14  0:21 ` Darrick J. Wong [this message]
2015-05-16 22:36   ` [PATCH 01/14] misc: fix Coverity bugs Theodore Ts'o
2015-05-14  0:21 ` [PATCH 02/14] undo-io: write out index block after every write Darrick J. Wong
2015-05-17  0:18   ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 03/14] misc: fix undo file setup Darrick J. Wong
2015-05-17  0:20   ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 04/14] filefrag: fix broken extent emulation and uninitialized variables Darrick J. Wong
2015-05-17  0:26   ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 05/14] e2fsck: fix buffer overrun in revoke block scanning Darrick J. Wong
2015-05-14 19:37   ` [PATCH v2 " Darrick J. Wong
2015-05-17  0:50     ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 06/14] e2fsck: convert block-mapped files to extents on bigalloc fs Darrick J. Wong
2015-05-17  0:51   ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 07/14] libext2fs: support allocating uninit blocks in bmap2() Darrick J. Wong
2015-05-17  0:54   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 08/14] libext2fs: find/alloc a range of empty blocks Darrick J. Wong
2015-05-17  1:02   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 09/14] libext2fs: add new hooks to support large allocations Darrick J. Wong
2015-06-11  0:08   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 10/14] libext2fs: implement fallocate Darrick J. Wong
2015-06-11  0:09   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 11/14] libext2fs: use fallocate for creating journals and hugefiles Darrick J. Wong
2015-05-17  3:39   ` Theodore Ts'o
2015-05-18 19:24     ` Darrick J. Wong
2015-05-18 21:18   ` [PATCH v2 " Darrick J. Wong
2015-06-11  0:12     ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 12/14] debugfs: implement fallocate Darrick J. Wong
2015-06-11  0:12   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 13/14] tests: test debugfs punch command Darrick J. Wong
2015-06-11  0:13   ` Theodore Ts'o
2015-05-18 21:17 ` [PATCH 15/14] libext2fs: remove unnecessary undo file flush calls Darrick J. Wong
2015-06-11  0:13   ` Theodore Ts'o
2015-06-05  1:38 ` [PATCH 16/14] libext2fs: require the inline data xattr on all inline data files Darrick J. Wong
2015-06-11  0:15   ` Theodore Ts'o
2015-07-23 21:12     ` Darrick J. Wong
     [not found] ` <20150514002240.10785.35238.stgit@birch.djwong.org>
2015-06-11  0:13   ` [PATCH 14/14] misc: add fuse2fs, a FUSE server for e2fsprogs (v4.3) Theodore Ts'o
2015-06-15 18:37     ` Darrick J. Wong
2015-06-15 19:21       ` Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150514002114.10785.41768.stgit@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).