]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fallocate: Use off_t instead of loff_t
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 18 Apr 2026 16:07:12 +0000 (18:07 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 18 Apr 2026 16:13:45 +0000 (18:13 +0200)
Eventually, the loff_t values are used as arguments for functions which
expect an off_t. Use off_t directly and, while at it, introduce a proper
range check in cvtnum.

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

index 244120caba92bcba2579231763624053a2dfb742..2b3b0e4bf2dd0c6ec1f8840c31620382eb59c69f 100644 (file)
@@ -108,14 +108,18 @@ static void __attribute__((__noreturn__)) usage(void)
        exit(EXIT_SUCCESS);
 }
 
-static loff_t cvtnum(char *s)
+static off_t cvtnum(char *s)
 {
        uintmax_t x;
 
        if (strtosize(s, &x))
                return -1LL;
+       if (x > (uintmax_t) SINT_MAX(off_t)) {
+               errno = ERANGE;
+               return -1;
+       }
 
-       return x;
+       return (off_t) x;
 }
 
 static void xfallocate(int fd, int mode, off_t offset, off_t length)
@@ -367,8 +371,8 @@ int main(int argc, char **argv)
        int     mode = 0;
        int     dig = 0;
        int     posix = 0;
-       loff_t  length = -2LL;
-       loff_t  offset = 0;
+       off_t   length = -2;
+       off_t   offset = 0;
 
        static const struct option longopts[] = {
            { "help",           no_argument,       NULL, 'h' },
@@ -462,13 +466,13 @@ int main(int argc, char **argv)
 
        if (dig || report) {
                /* for --dig-holes and --report-holes the default is analyze all file */
-               if (length == -2LL)
+               if (length == -2)
                        length = 0;
                if (length < 0)
                        errx(EXIT_FAILURE, _("invalid length"));
        } else {
                /* it's safer to require the range specification (--length --offset) */
-               if (length == -2LL)
+               if (length == -2)
                        errx(EXIT_FAILURE, _("no length argument specified"));
                if (length <= 0)
                        errx(EXIT_FAILURE, _("invalid length"));