]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fsck.minix: fix endless loop and out of stack
authorKarel Zak <kzak@redhat.com>
Wed, 1 Jun 2016 12:55:15 +0000 (14:55 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Jun 2016 12:55:15 +0000 (14:55 +0200)
It seems there is no elegant way how to recovery if a directory i_zone
(and i_size) is out of reality. Let's require human interaction to
avoid endless loop when executed with --auto, etc.

Addresses: https://github.com/karelzak/util-linux/issues/228
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fsck.minix.c

index 467f9dfc8c975a94d391d5c7d22f7d2872414b71..726f5daaf3dd4b2809025742e55808656bf0d6d7 100644 (file)
@@ -296,6 +296,16 @@ check_mount(void) {
        return;
 }
 
+
+static int is_valid_zone_nr(unsigned short nr)
+{
+       if (nr < get_first_zone())
+               return 0;
+       else if (nr >= get_nzones())
+               return 0;
+       return 1;
+}
+
 /* check_zone_nr checks to see that *nr is a valid zone nr.  If it isn't, it
  * will possibly be repaired.  Check_zone_nr sets *corrected if an error was
  * corrected, and returns the zone (0 for no zone or a bad zone-number).  */
@@ -1087,6 +1097,12 @@ recursive_check(unsigned int ino) {
                printf(_("%s: bad directory: size < 32"), current_name);
                errors_uncorrected = 1;
        }
+
+       if ((!repair || automatic) && !is_valid_zone_nr(*dir->i_zone)) {
+               get_current_name();
+               printf(_("%s: bad directory: invalid i_zone, use --repair to fix\n"), current_name);
+               return;
+       }
        for (offset = 0; offset < dir->i_size; offset += dirsize)
                check_file(dir, offset);
 }