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:04:40 +0000
commit70f6696f0f90b0de9dba554faafc50ec3444443d (patch)
tree88535cc3237ff9ba77d5bbc1cb1146f62aa693b4
parente04975952eae337c9f0dc26a945bafb3ac75c640 (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);