All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Moryakov <ant.v.moryakov@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH] FIX: NO_CAST.INTEGER_OVERFLOW in ubirsvol.c
Date: Fri,  6 Dec 2024 15:37:44 +0300	[thread overview]
Message-ID: <20241206123744.60649-1-ant.v.moryakov@gmail.com> (raw)

Report of the static analyzer:
The value of an arithmetic expression 'vol_info.leb_size * args.lebs' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic

Corrections explained:
the fix ensures values ​​are checked before multiplication. 
an exception check for the negativity of vol_info.leb_size and args.lebs was added, as well as casting vol_info.leb_size to uint64_t

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

---
 ubi-utils/ubirsvol.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ubi-utils/ubirsvol.c b/ubi-utils/ubirsvol.c
index 0854abc..87286d4 100644
--- a/ubi-utils/ubirsvol.c
+++ b/ubi-utils/ubirsvol.c
@@ -230,8 +230,10 @@ int main(int argc, char * const argv[])
 		}
 	}
 
-	if (args.lebs != -1)
-		args.bytes = vol_info.leb_size * args.lebs;
+	if (args.lebs != -1){
+		if(vol_info.leb_size > 0 && args.lebs > 0)
+			args.bytes =(uint64_t)vol_info.leb_size * args.lebs;
+	}
 
 	err = ubi_rsvol(libubi, args.node, args.vol_id, args.bytes);
 	if (err) {
-- 
2.30.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

             reply	other threads:[~2024-12-06 12:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06 12:37 Anton Moryakov [this message]
2024-12-07  5:00 ` [PATCH] FIX: NO_CAST.INTEGER_OVERFLOW in ubirsvol.c Zhihao Cheng
  -- strict thread matches above, loose matches on Subject: below --
2024-12-09 21:09 Anton Moryakov
2024-12-06 12:34 Anton Moryakov

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=20241206123744.60649-1-ant.v.moryakov@gmail.com \
    --to=ant.v.moryakov@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.