fsck.minix: fix endless loop and out of stack

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>
This commit is contained in:
Karel Zak 2016-06-01 14:55:15 +02:00
parent d1b7bfe506
commit 65c74885df
1 changed files with 16 additions and 0 deletions

View 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);
}