linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiao Ni <xni@redhat.com>
To: mariusz.tkaczyk@linux.intel.com
Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org
Subject: [PATCH 04/14] mdadm/Incremental: fix coverity issues.
Date: Fri, 19 Jul 2024 17:52:09 +0800	[thread overview]
Message-ID: <20240719095219.9705-5-xni@redhat.com> (raw)
In-Reply-To: <20240719095219.9705-1-xni@redhat.com>

There are two issues PW.PARAMETER_HIDDEN and INTEGER_OVERFLOW

Signed-off-by: Xiao Ni <xni@redhat.com>
---
 Incremental.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/Incremental.c b/Incremental.c
index 83db0712..508e2c7c 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -770,7 +770,7 @@ static int count_active(struct supertype *st, struct mdinfo *sra,
 			replcnt++;
 		st->ss->free_super(st);
 	}
-	if (max_journal_events >= max_events - 1)
+	if (max_events > 0 && max_journal_events >= max_events - 1)
 		bestinfo->journal_clean = 1;
 
 	if (!avail)
@@ -1113,7 +1113,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
 		int fd = -1;
 		struct mdinfo info;
 		struct supertype *st2 = NULL;
-		char *devname = NULL;
+		char *dev_name = NULL;
 		unsigned long long devsectors;
 		char *pathlist[2];
 
@@ -1142,14 +1142,14 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
 		domain_free(domlist);
 		domlist = NULL;
 
-		if (asprintf(&devname, "/dev/disk/by-path/%s", de->d_name) != 1) {
-			devname = NULL;
+		if (asprintf(&dev_name, "/dev/disk/by-path/%s", de->d_name) != 1) {
+			dev_name = NULL;
 			goto next;
 		}
-		fd = open(devname, O_RDONLY);
+		fd = open(dev_name, O_RDONLY);
 		if (fd < 0)
 			goto next;
-		if (get_dev_size(fd, devname, &devsectors) == 0)
+		if (get_dev_size(fd, dev_name, &devsectors) == 0)
 			goto next;
 		devsectors >>= 9;
 
@@ -1188,8 +1188,8 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
 		if (chosen == NULL || chosen_size < info.component_size) {
 			chosen_size = info.component_size;
 			free(chosen);
-			chosen = devname;
-			devname = NULL;
+			chosen = dev_name;
+			dev_name = NULL;
 			if (chosen_st) {
 				chosen_st->ss->free_super(chosen_st);
 				free(chosen_st);
@@ -1199,7 +1199,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
 		}
 
 	next:
-		free(devname);
+		free(dev_name);
 		domain_free(domlist);
 		dev_policy_free(pol2);
 		if (st2)
@@ -1246,7 +1246,7 @@ static int is_bare(int dfd)
 
 	/* OK, first 4K appear blank, try the end. */
 	get_dev_size(dfd, NULL, &size);
-	if (lseek(dfd, size-4096, SEEK_SET) < 0 ||
+	if ((size >= 4096 && lseek(dfd, size-4096, SEEK_SET) < 0) ||
 	    read(dfd, buf, 4096) != 4096)
 		return 0;
 
-- 
2.41.0


  parent reply	other threads:[~2024-07-19  9:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-19  9:52 [PATCH V2 00/14] mdadm: fix coverity issues Xiao Ni
2024-07-19  9:52 ` [PATCH 01/14] mdadm/Grow: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-19  9:52 ` [PATCH 02/14] mdadm/Grow: fix coverity issue RESOURCE_LEAK Xiao Ni
2024-07-19  9:52 ` [PATCH 03/14] mdadm/Grow: fix coverity issue STRING_OVERFLOW Xiao Ni
2024-07-19  9:52 ` Xiao Ni [this message]
2024-07-19  9:52 ` [PATCH 05/14] mdadm/mdmon: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-19  9:52 ` [PATCH 06/14] mdadm/mdmon: fix coverity issue RESOURCE_LEAK Xiao Ni
2024-07-19  9:52 ` [PATCH 07/14] mdadm/mdopen: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-19  9:52 ` [PATCH 08/14] mdadm/mdopen: fix coverity issue STRING_OVERFLOW Xiao Ni
2024-07-19  9:52 ` [PATCH 09/14] mdadm/mdstat: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-19  9:52 ` [PATCH 10/14] mdadm/super0: fix coverity issue CHECKED_RETURN and EVALUATION_ORDER Xiao Ni
2024-07-19  9:52 ` [PATCH 11/14] mdadm/super1: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-19  9:52 ` [PATCH 12/14] mdadm/super1: fix coverity issue DEADCODE Xiao Ni
2024-07-19  9:52 ` [PATCH 13/14] mdadm/super1: fix coverity issue EVALUATION_ORDER Xiao Ni
2024-07-19  9:52 ` [PATCH 14/14] mdadm/super1: fix coverity issue RESOURCE_LEAK Xiao Ni
  -- strict thread matches above, loose matches on Subject: below --
2024-07-22  8:17 [PATCH V3 00/14] mdadm: fix coverity issues Xiao Ni
2024-07-22  8:17 ` [PATCH 04/14] mdadm/Incremental: " Xiao Ni
2024-07-26  7:14 [PATCH V4 00/14] mdadm: " Xiao Ni
2024-07-26  7:14 ` [PATCH 04/14] mdadm/Incremental: " Xiao Ni

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=20240719095219.9705-5-xni@redhat.com \
    --to=xni@redhat.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=mariusz.tkaczyk@linux.intel.com \
    --cc=ncroxon@redhat.com \
    /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).