]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: don't assign cvtnum() return to unsigned var
authorEric Sandeen <sandeen@sandeen.net>
Thu, 3 Dec 2009 19:20:54 +0000 (13:20 -0600)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 3 Dec 2009 19:20:54 +0000 (13:20 -0600)
cvtnum() returns -1LL for unparseable values, but if we
assign to a signed var, we can't test it:

There are problems in fadvise, mincore & madvise.

xfs_io> mincore 0 xxx
range (0:0) is beyond mapping (0:1048576)

For mincore & madvise, se a temporary signed var so we
can detect the error:

xfs_io> mincore 0 xxx
non-numeric length argument -- xxx

and also test whether it may overflow a size_t for
mincore & madvise.

For fadvise, posix_fadvise64 wants an off_t anyway so just
switch to that.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Reviewed-by: Christoph Hellwig <hch@lst.de>
io/fadvise.c
io/madvise.c
io/mincore.c

index b5ab65227d58900253aaef188464a09d131185cb..5a76ebb231ac6468335cb63988df582ca5641e73 100644 (file)
@@ -52,8 +52,7 @@ fadvise_f(
        int             argc,
        char            **argv)
 {
-       off64_t         offset = 0;
-       size_t          length = 0;
+       off64_t         offset = 0, length = 0;
        int             c, range = 0, advise = POSIX_FADV_NORMAL;
 
        while ((c = getopt(argc, argv, "dnrsw")) != EOF) {
index 694cd415c3bf4faadc06415d027a5d4ae7ce276d..cd16a4cb0c4061f43e8626c6acc93ad1f2b98a3a 100644 (file)
@@ -52,7 +52,7 @@ madvise_f(
        int             argc,
        char            **argv)
 {
-       off64_t         offset;
+       off64_t         offset, llength;
        size_t          length;
        void            *start;
        int             advise = MADV_NORMAL, c;
@@ -89,12 +89,17 @@ madvise_f(
                        return 0;
                }
                optind++;
-               length = cvtnum(blocksize, sectsize, argv[optind]);
-               if (length < 0) {
+               llength = cvtnum(blocksize, sectsize, argv[optind]);
+               if (llength < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[optind]);
                        return 0;
-               }
+               } else if (llength > (size_t)llength) {
+                       printf(_("length argument too large -- %lld\n"),
+                               llength);
+                       return 0;
+               } else
+                       length = (size_t)llength;
        } else {
                return command_usage(&madvise_cmd);
        }
index f863f8480878bac2037b5d072988ca62ac2741b4..d534540830b3d9f546153fd76930e6a8a9385a1e 100644 (file)
@@ -30,7 +30,7 @@ mincore_f(
        int             argc,
        char            **argv)
 {
-       off64_t         offset;
+       off64_t         offset, llength;
        size_t          length;
        size_t          blocksize, sectsize;
        void            *start;
@@ -49,12 +49,17 @@ mincore_f(
                                argv[1]);
                        return 0;
                }
-               length = cvtnum(blocksize, sectsize, argv[2]);
-               if (length < 0) {
+               llength = cvtnum(blocksize, sectsize, argv[2]);
+               if (llength < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[2]);
                        return 0;
-               }
+               } else if (llength > (size_t)llength) {
+                       printf(_("length argument too large -- %lld\n"),
+                               llength);
+                       return 0;
+               } else
+                       length = (size_t)llength;
        } else {
                return command_usage(&mincore_cmd);
        }