]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
shred: fix overflow checking of command-line options
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 10 May 2014 18:42:38 +0000 (11:42 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 10 May 2014 18:43:15 +0000 (11:43 -0700)
* src/shred.c (main): Limit -n (number of passes) value to
ULONG_MAX, not to UINT32_MAX, since the vars are unsigned long.
Limit the -s (file size) value to OFF_T_MAX.

src/shred.c

index 607c6be159b51aa49faad993f4254f611da3e6eb..f4347e002a18741b547596b60095695684a791d6 100644 (file)
@@ -1231,7 +1231,7 @@ main (int argc, char **argv)
           {
             uintmax_t tmp;
             if (xstrtoumax (optarg, NULL, 10, &tmp, NULL) != LONGINT_OK
-                || MIN (UINT32_MAX, SIZE_MAX / sizeof (int)) < tmp)
+                || MIN (ULONG_MAX, SIZE_MAX / sizeof (int)) <= tmp)
               {
                 error (EXIT_FAILURE, 0, _("%s: invalid number of passes"),
                        quotearg_colon (optarg));
@@ -1256,9 +1256,10 @@ main (int argc, char **argv)
 
         case 's':
           {
-            uintmax_t tmp;
-            if (xstrtoumax (optarg, NULL, 0, &tmp, "cbBkKMGTPEZY0")
-                != LONGINT_OK)
+            intmax_t tmp;
+            if ((xstrtoimax (optarg, NULL, 0, &tmp, "cbBkKMGTPEZY0")
+                 != LONGINT_OK)
+                || OFF_T_MAX < tmp)
               {
                 error (EXIT_FAILURE, 0, _("%s: invalid file size"),
                        quotearg_colon (optarg));