]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: fix overflow possiblity
authorSteven Seungcheol Lee <sc108.lee@samsung.com>
Fri, 3 Nov 2023 00:53:50 +0000 (09:53 +0900)
committerDaniel Wagner <wagi@monom.org>
Fri, 3 Nov 2023 08:53:51 +0000 (09:53 +0100)
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 <sc108.lee@samsung.com>
[dwagner: added commit message]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
nvme.c

diff --git a/nvme.c b/nvme.c
index 6462ec3dd957564aa9d7571a8d160349a6f304b6..1c4cf42443ca101837bbe2c0d340031985867da9 100644 (file)
--- 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);