From: Tobias Stoeckmann Date: Tue, 10 Mar 2026 17:11:02 +0000 (+0100) Subject: mkfs.cramfs: Properly check mmap results X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71a4b1e94405be6b5cf9971b7376e2c042ffb651;p=thirdparty%2Futil-linux.git mkfs.cramfs: Properly check mmap results The POSIX manual page states that the error return value is MAP_FAILED. Sync with all other mmap checks throughout util-linux. Also, test an mmap call which previously was not tested. Signed-off-by: Tobias Stoeckmann --- diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index 0b6e04de6..b456db6a5 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -663,6 +663,8 @@ static unsigned int write_file(char *file, char *base, unsigned int offset) if (fd < 0) err(MKFS_EX_ERROR, _("cannot open %s"), file); buf = mmap(NULL, image_length, PROT_READ, MAP_PRIVATE, fd, 0); + if (buf == MAP_FAILED) + err(MKFS_EX_ERROR, _("cannot map %s"), file); memcpy(base + offset, buf, image_length); munmap(buf, image_length); if (close (fd) < 0) @@ -853,7 +855,7 @@ int main(int argc, char **argv) MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (-1 == (int) (long) rom_image) + if (MAP_FAILED == rom_image) err(MKFS_EX_ERROR, _("ROM image map")); /* Skip the first opt_pad bytes for boot loader code */