]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(dracut-install): broken calls to mmap with 0 length
authorJames Le Cuirot <jlecuirot@microsoft.com>
Tue, 12 Aug 2025 09:15:58 +0000 (10:15 +0100)
committerBenjamin Drung <bdrung@ubuntu.com>
Thu, 14 Aug 2025 19:28:35 +0000 (21:28 +0200)
This results in an invalid argument error, so check for 0 length first.

Fixes: https://bugs.gentoo.org/961340
Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
src/install/dracut-install.c

index 6ea4d5a293952edeca9574fc59e5cbdc91e666bf..deaf54f85eb44b29b705d263be80d5308900dde2 100644 (file)
@@ -631,7 +631,11 @@ static char *check_lib_match(const char *dirname, const char *basename, const ch
         if (fstat(fd, &sb) < 0)
                 goto finish2;
 
-        void *map = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+        size_t lib_len = sb.st_size;
+        if (lib_len == 0)
+                goto finish2;
+
+        void *map = mmap(NULL, lib_len, PROT_READ, MAP_PRIVATE, fd, 0);
         if (map == MAP_FAILED)
                 goto finish2;
 
@@ -1148,6 +1152,9 @@ static int resolve_deps(const char *src, Hashmap *pdeps)
         }
 
         size_t src_len = sb.st_size;
+        if (src_len == 0)
+                return 0;
+
         void *map = mmap(NULL, src_len, PROT_READ, MAP_PRIVATE, fd, 0);
         if (map == MAP_FAILED) {
                 log_error("ERROR: cannot mmap '%s': %m", fullsrcpath);