From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Anton Moryakov <ant.v.moryakov@gmail.com>,
<linux-mtd@lists.infradead.org>
Subject: Re: [PATCH mtd-utils] ubi-utils: Fix integer overflow in mtdinfo.c
Date: Mon, 16 Dec 2024 09:08:52 +0800 [thread overview]
Message-ID: <5849276f-bc8e-4846-c429-aa69d586ddc2@huawei.com> (raw)
In-Reply-To: <20241214123105.75618-1-ant.v.moryakov@gmail.com>
在 2024/12/14 20:31, Anton Moryakov 写道:
> Report of the static analyzer:
> The value of an arithmetic expression 'reginfo->offset + i * reginfo->erasesize' is a subject to overflow
> because its operands are not cast to a larger data type before performing arithmetic
>
> Corrections explained:
> Added casting i and start to unsigned long long
>
> Triggers found by static analyzer Svace.
>
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
>
> ---
> ubi-utils/mtdinfo.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> diff --git a/ubi-utils/mtdinfo.c b/ubi-utils/mtdinfo.c
> index 7dff0de..12d35eb 100644
> --- a/ubi-utils/mtdinfo.c
> +++ b/ubi-utils/mtdinfo.c
> @@ -185,7 +185,7 @@ static void print_ubi_info(const struct mtd_info *mtd_info,
> static void print_region_map(const struct mtd_dev_info *mtd, int fd,
> const region_info_t *reginfo)
> {
> - unsigned long start;
> + unsigned long long start;
> int i, width;
> int ret_locked, errno_locked, ret_bad, errno_bad;
>
> @@ -203,7 +203,7 @@ static void print_region_map(const struct mtd_dev_info *mtd, int fd,
> ret_locked = ret_bad = errno_locked = errno_bad = 0;
>
> for (i = 0; i < reginfo->numblocks; ++i) {
> - start = reginfo->offset + i * reginfo->erasesize;
> + start = reginfo->offset + (unsigned long long)i * reginfo->erasesize;
> printf(" %*i: %08lx ", width, i, start);
>
> if (ret_locked != -1) {
>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2024-12-16 1:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-14 12:31 [PATCH mtd-utils] ubi-utils: Fix integer overflow in mtdinfo.c Anton Moryakov
2024-12-16 1:08 ` Zhihao Cheng [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-12-14 10:51 Anton Moryakov
2024-12-14 12:19 ` Zhihao Cheng
2024-12-13 13:15 Anton Moryakov
2024-12-14 2:56 ` Zhihao Cheng
2024-12-12 17:29 Anton Moryakov
2024-12-12 17:13 Anton Moryakov
2024-12-13 2:29 ` 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=5849276f-bc8e-4846-c429-aa69d586ddc2@huawei.com \
--to=chengzhihao1@huawei.com \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox