aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunheeee <yunhe27@126.com>2026-09-26 03:10:04 +0000
committerXin LI <delphij@FreeBSD.org>2026-10-02 05:05:44 +0000
commitec3ebfaf9fd37ab937141f6b4fca548b1c9173a3 (patch)
treec81f30f6ce884ae4a9be92185af678b4d5997e92
parent2ccc24409759cf1f7fb0d67ef429da9dd40f6ff8 (diff)
MFC: fsck_msdosfs: fix head bitmap over-allocation on 32-bit platforms
bitmap_ctor() computed the allocation size as roundup2(bits, LONG_BIT) / (LONG_BIT / 8) The dividend is a count of bits, so converting it to bytes requires dividing by 8 (bits per byte), not by LONG_BIT / 8 (bytes per long). The two divisors happen to coincide on LP64, but on ILP32 platforms the head bitmap was allocated at twice the required size; for a FAT32 file system with close to 2^28 clusters, that is 64 MiB instead of 32 MiB. The extra half of the allocation was never accessed, so there is no functional change other than the reduced memory footprint. Pull Request: https://github.com/freebsd/freebsd-src/pull/2440 (cherry picked from commit 269002da453895fc935101afefeb02d2c7d10360)
-rw-r--r--sbin/fsck_msdosfs/fat.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sbin/fsck_msdosfs/fat.c b/sbin/fsck_msdosfs/fat.c
index 7d0ad9a595cf..ef788c9826a4 100644
--- a/sbin/fsck_msdosfs/fat.c
+++ b/sbin/fsck_msdosfs/fat.c
@@ -121,7 +121,7 @@ bitmap_count(long_bitmap_t *lbp)
static int
bitmap_ctor(long_bitmap_t *lbp, size_t bits, bool allone)
{
- size_t bitmap_size = roundup2(bits, LONG_BIT) / (LONG_BIT / 8);
+ size_t bitmap_size = roundup2(bits, LONG_BIT) / 8;
free(lbp->map);
lbp->map = calloc(1, bitmap_size);