* [PATCH mtd-utils] ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c
@ 2024-12-10 0:07 Anton Moryakov
2024-12-10 1:18 ` Zhihao Cheng
0 siblings, 1 reply; 3+ messages in thread
From: Anton Moryakov @ 2024-12-10 0:07 UTC (permalink / raw)
To: linux-mtd, chengzhihao1; +Cc: Anton Moryakov
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.
Added casting vol_info.leb_size to long long
Triggers found by static analyzer Svace.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
ubi-utils/ubirsvol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ubi-utils/ubirsvol.c b/ubi-utils/ubirsvol.c
index 0854abc..73d2f68 100644
--- a/ubi-utils/ubirsvol.c
+++ b/ubi-utils/ubirsvol.c
@@ -231,7 +231,7 @@ int main(int argc, char * const argv[])
}
if (args.lebs != -1)
- args.bytes = vol_info.leb_size * args.lebs;
+ args.bytes = (long long)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/
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH mtd-utils] ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c
2024-12-10 0:07 [PATCH mtd-utils] ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c Anton Moryakov
@ 2024-12-10 1:18 ` Zhihao Cheng
0 siblings, 0 replies; 3+ messages in thread
From: Zhihao Cheng @ 2024-12-10 1:18 UTC (permalink / raw)
To: Anton Moryakov, linux-mtd
在 2024/12/10 8:07, Anton Moryakov 写道:
> 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.
> Added casting vol_info.leb_size to long long
>
> Triggers found by static analyzer Svace.
>
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
>
> ---
> ubi-utils/ubirsvol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
>
> diff --git a/ubi-utils/ubirsvol.c b/ubi-utils/ubirsvol.c
> index 0854abc..73d2f68 100644
> --- a/ubi-utils/ubirsvol.c
> +++ b/ubi-utils/ubirsvol.c
> @@ -231,7 +231,7 @@ int main(int argc, char * const argv[])
> }
>
> if (args.lebs != -1)
> - args.bytes = vol_info.leb_size * args.lebs;
> + args.bytes = (long long)vol_info.leb_size * args.lebs;
>
> err = ubi_rsvol(libubi, args.node, args.vol_id, args.bytes);
> if (err) {
>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH mtd-utils] ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c
@ 2024-12-07 14:18 Anton Moryakov
0 siblings, 0 replies; 3+ messages in thread
From: Anton Moryakov @ 2024-12-07 14:18 UTC (permalink / raw)
To: linux-mtd; +Cc: Anton Moryakov
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 long long
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 = (long long)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/
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-10 1:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-10 0:07 [PATCH mtd-utils] ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c Anton Moryakov
2024-12-10 1:18 ` Zhihao Cheng
-- strict thread matches above, loose matches on Subject: below --
2024-12-07 14:18 Anton Moryakov
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.