[PATCH 3/7] builtin/bugreport.c: avoid size_t overflow
- From
Victoria Dye via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Aug 1, 2022, 21:14 UTC
- Message-ID
- <e8abfdfa892f5670ed411ed6daef26a4ffa1bfe6.1659388498.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1310.git.1659388498.gitgitgadget@gmail.com>
From: Victoria Dye <vdye@github.com>
Avoid size_t overflow when reporting the available disk space in 'get_disk_info' by casting the block size and available block count to 'uint64_t' before multiplying them. Without this change, 'st_mult' would (correctly) report size_t overflow on 32-bit systems at or exceeding 2^32 bytes of available space.
Signed-off-by: Victoria Dye <vdye@github.com> --- builtin/bugreport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 35b1fc48bf1..720889a37ad 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -258,7 +258,7 @@ static int get_disk_info(struct strbuf *out) } strbuf_addf(out, "Available space on '%s': ", buf.buf); - strbuf_humanise_bytes(out, st_mult(stat.f_bsize, stat.f_bavail)); + strbuf_humanise_bytes(out, (uint64_t)stat.f_bsize * (uint64_t)stat.f_bavail); strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag); strbuf_release(&buf); #endif
-- gitgitgadget