From ae31cbde090e815b4e97889428fd7b14b8ec43e3 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Wed, 19 Jan 2022 13:44:33 +0200 Subject: [PATCH] Fix an overflow in blkcnt_t gpt_last_lba If CONFIG_FS_LARGEFILE is not defined, the calculation overflows for larger disks, since blkcnt_t is 32 bits. Signed-off-by: Jukka Laitinen --- fs/partition/fs_gpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/partition/fs_gpt.c b/fs/partition/fs_gpt.c index df639cc172a..90c9ee8dd0c 100644 --- a/fs/partition/fs_gpt.c +++ b/fs/partition/fs_gpt.c @@ -173,8 +173,8 @@ static const struct gpt_guid_s g_null_guid; static inline blkcnt_t gpt_last_lba(FAR struct partition_state_s *state) { - return (state->nblocks * state->blocksize + GPT_BLOCK_SIZE - 1) / - GPT_BLOCK_SIZE - 1; + return (((uint64_t)state->nblocks) * state->blocksize + GPT_BLOCK_SIZE - 1) + / GPT_BLOCK_SIZE - 1; } /****************************************************************************