]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: reject 64bit badblocks numbers
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 23 Oct 2013 23:43:32 +0000 (19:43 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 23 Oct 2013 23:56:21 +0000 (19:56 -0400)
Don't accept block numbers larger than 2^32 for the badblocks list,
and don't run badblocks on them either.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/read_bb_file.c
misc/badblocks.c

index 7d7bb7aa5306b19a7fa6ea7eb52b472d0ef57a30..8d1ad1a53ef4836bd5ac0f85df3112464a740f1d 100644 (file)
@@ -39,7 +39,7 @@ errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
                                               void *priv_data))
 {
        errcode_t       retval;
-       blk_t           blockno;
+       blk64_t         blockno;
        int             count;
        char            buf[128];
 
@@ -55,9 +55,12 @@ errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
        while (!feof (f)) {
                if (fgets(buf, sizeof(buf), f) == NULL)
                        break;
-               count = sscanf(buf, "%u", &blockno);
+               count = sscanf(buf, "%llu", &blockno);
                if (count <= 0)
                        continue;
+               /* Badblocks isn't going to be updated for 64bit */
+               if (blockno >> 32)
+                       return EOVERFLOW;
                if (fs &&
                    ((blockno < fs->super->s_first_data_block) ||
                     (blockno >= ext2fs_blocks_count(fs->super)))) {
index c9e47c7cb919e0e17feae88288966b404ca1fed5..432c17b1beabe69c124b6c154f452afdbd52a1c7 100644 (file)
@@ -1047,6 +1047,7 @@ int main (int argc, char ** argv)
                                  unsigned int);
        int open_flag;
        long sysval;
+       blk64_t inblk;
 
        setbuf(stdout, NULL);
        setbuf(stderr, NULL);
@@ -1200,10 +1201,17 @@ int main (int argc, char ** argv)
                first_block = parse_uint(argv[optind], _("first block"));
        } else first_block = 0;
        if (first_block >= last_block) {
-           com_err (program_name, 0, _("invalid starting block (%lu): must be less than %lu"),
-                    (unsigned long) first_block, (unsigned long) last_block);
+           com_err (program_name, 0, _("invalid starting block (%llu): must be less than %llu"),
+                    first_block, last_block);
            exit (1);
        }
+       /* ext2 badblocks file can't handle large values */
+       if (last_block >> 32) {
+               com_err(program_name, EOVERFLOW,
+                       _("invalid end block (%llu): must be 32-bit value"),
+                       last_block);
+               exit(1);
+       }
        if (w_flag)
                check_mount(device_name);
 
@@ -1262,13 +1270,20 @@ int main (int argc, char ** argv)
 
        if (in) {
                for(;;) {
-                       switch(fscanf (in, "%u\n", &next_bad)) {
+                       switch (fscanf(in, "%llu\n", &inblk)) {
                                case 0:
                                        com_err (program_name, 0, "input file - bad format");
                                        exit (1);
                                case EOF:
                                        break;
                                default:
+                                       if (inblk >> 32) {
+                                               com_err(program_name,
+                                                       EOVERFLOW,
+                                                       _("while adding to in-memory bad block list"));
+                                               exit(1);
+                                       }
+                                       next_bad = inblk;
                                        errcode = ext2fs_badblocks_list_add(bb_list,next_bad);
                                        if (errcode) {
                                                com_err (program_name, errcode, _("while adding to in-memory bad block list"));