[PATCH mtd-utils] ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c
Zhihao Cheng
chengzhihao1 at huawei.com
Mon Dec 9 17:18:16 PST 2024
在 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 at gmail.com>
>
> ---
> ubi-utils/ubirsvol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Zhihao Cheng <chengzhihao1 at 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) {
>
More information about the linux-mtd
mailing list