From 024395655ddc95955e96663de70360f92cc3d0f9 Mon Sep 17 00:00:00 2001 From: Steven Seungcheol Lee Date: Fri, 3 Nov 2023 09:53:50 +0900 Subject: [PATCH] nvme: fix overflow possiblity The implicit type conversion will expand both operands to the type int and not unsigned long long as the result expects. Promote the first operand to the target type. Obviously the multiplication can still overflow, but this is a different problem. Signed-off-by: Steven Seungcheol Lee [dwagner: added commit message] Signed-off-by: Daniel Wagner --- nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvme.c b/nvme.c index 6462ec3d..1c4cf424 100644 --- a/nvme.c +++ b/nvme.c @@ -7319,7 +7319,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char nblocks = ((buffer_size + (logical_block_size - 1)) / logical_block_size) - 1; /* Update the data size based on the required block count */ - buffer_size = (nblocks + 1) * logical_block_size; + buffer_size = ((unsigned long long)nblocks + 1) * logical_block_size; } buffer = nvme_alloc_huge(buffer_size, &huge); -- 2.49.0