From: Steven Seungcheol Lee Date: Fri, 3 Nov 2023 00:53:50 +0000 (+0900) Subject: nvme: fix overflow possiblity X-Git-Tag: v2.7~106 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=024395655ddc95955e96663de70360f92cc3d0f9;p=users%2Fsagi%2Fnvme-cli.git 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 --- 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);