From: Anton Moryakov <ant.v.moryakov@gmail.com>
To: chengzhihao1@huawei.com, linux-mtd@lists.infradead.org
Cc: Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH mtd-utils] misc-utils: Fix integer overflow in docfdisk.c
Date: Tue, 17 Dec 2024 15:44:22 +0300 [thread overview]
Message-ID: <20241217124422.245489-1-ant.v.moryakov@gmail.com> (raw)
Report of the static analyzer:
Possible integer underflow: left operand is tainted. An integer underflow may occur due to arithmetic operation (subtraction) between variable 'block' and value '1', when 'block' is tainted { [-2147483648, 2147483647] }
Corrections explained:
Added the block <= 0 check, which prevents integer underflow when calculating block - 1 and ensures that block is always positive.
Triggers found by static analyzer Svace.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
misc-utils/docfdisk.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/misc-utils/docfdisk.c b/misc-utils/docfdisk.c
index 486ce29..e473ceb 100644
--- a/misc-utils/docfdisk.c
+++ b/misc-utils/docfdisk.c
@@ -255,6 +255,10 @@ int main(int argc, char **argv)
ip->firstUnit = cpu_to_le32(block);
if (!nblocks[i])
nblocks[i] = totblocks - block;
+ if (block <= 0) {
+ fprintf(stderr, "Error: Invalid block value (%d). Block must be greater than 0.\n", block);
+ return -1;
+ }
ip->virtualUnits = cpu_to_le32(nblocks[i]);
block += nblocks[i];
ip->lastUnit = cpu_to_le32(block-1);
--
2.30.2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next reply other threads:[~2024-12-17 12:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 12:44 Anton Moryakov [this message]
2024-12-18 1:30 ` [PATCH mtd-utils] misc-utils: Fix integer overflow in docfdisk.c Zhihao Cheng
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=20241217124422.245489-1-ant.v.moryakov@gmail.com \
--to=ant.v.moryakov@gmail.com \
--cc=chengzhihao1@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox