]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Fix error checking of badblock's last-block and start-block arguments
authorTheodore Ts'o <tytso@mit.edu>
Mon, 4 Jun 2007 05:49:51 +0000 (01:49 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 4 Jun 2007 05:49:51 +0000 (01:49 -0400)
Addresses Debian Bug: #416477

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
misc/ChangeLog
misc/badblocks.c

index 0923f9445dc619450ea78d51bc6a095c815146b5..5b680c5f938b1640367ab6426c2e77a3f1a828a0 100644 (file)
@@ -1,3 +1,8 @@
+2007-06-04  Theodore Tso  <tytso@mit.edu>
+
+       * badblocks.c (main): Fix error checking of the last-block and
+               start-block arguments.  (Addresses Debian Bug: #416477)
+
 2007-05-31  Theodore Tso  <tytso@mit.edu>
 
        * mke2fs.c (parse_extended_opts): Free allocated buf on return
index 8f48c88bd3e3dc3b1148e4b7dfe216a22f1ca8e4..88c5a745d441584dcb3e10642e060dd2197f3c2b 100644 (file)
@@ -46,6 +46,7 @@ extern int optind;
 #include <unistd.h>
 #include <setjmp.h>
 #include <time.h>
+#include <limits.h>
 
 #include <sys/ioctl.h>
 #include <sys/types.h>
@@ -987,24 +988,31 @@ int main (int argc, char ** argv)
                        exit(1);
                }
        } else {
-               last_block = strtoul (argv[optind], &tmp, 0) + 1;
-               if (*tmp) {
+               errno = 0;
+               last_block = strtoul (argv[optind], &tmp, 0);
+               printf("last_block = %d (%s)\n", last_block, argv[optind]);
+               if (*tmp || errno || 
+                   (last_block == ULONG_MAX && errno == ERANGE)) {
                        com_err (program_name, 0, _("invalid blocks count - %s"),
                                 argv[optind]);
                        exit (1);
                }
+               last_block++;
                optind++;
        }
        if (optind <= argc-1) {
+               errno = 0;
                from_count = strtoul (argv[optind], &tmp, 0);
-               if (*tmp) {
+               printf("from_count = %d\n", from_count);
+               if (*tmp || errno ||
+                   (from_count == ULONG_MAX && errno == ERANGE)) {
                        com_err (program_name, 0, _("invalid starting block - %s"),
                                 argv[optind]);
                        exit (1);
                }
        } else from_count = 0;
        if (from_count >= last_block) {
-           com_err (program_name, 0, _("invalid blocks range: %lu-%lu"),
+           com_err (program_name, 0, _("invalid starting block (%d): must be less than %lu"),
                     (unsigned long) from_count, (unsigned long) last_block);
            exit (1);
        }