]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fallocate: Add range check
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 18 Apr 2026 16:17:13 +0000 (18:17 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 18 Apr 2026 16:17:13 +0000 (18:17 +0200)
Make sure that offset + length does not overflow off_t.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
sys-utils/fallocate.c

index 622e0c39c1923904d296519cdc8bdd5503bfef35..ff063fcd5a952b84ca1090cd7c28934fe96b9c21 100644 (file)
@@ -479,6 +479,10 @@ int main(int argc, char **argv)
                if (length == 0)
                        errx(EXIT_FAILURE, _("invalid length"));
        }
+       if (length > SINT_MAX(off_t) - offset) {
+               errno = ERANGE;
+               err(EXIT_FAILURE, _("invalid range specified"));
+       }
 
        /* O_CREAT makes sense only for the default fallocate(2) behavior
         * when mode is no specified and new space is allocated */