diff --git a/ChangeLog b/ChangeLog index 649dc9a7c..1e278ad6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-11-30 Yoshinori K. Okuji + + * stage2/disk_io.c (rawread): Make sure that SECTOR is valid. + If not, set ERRNUM to ERR_GEOM and return zero. This check is + critical when a partition table is corrupted. + 2002-11-28 Yoshinori K. Okuji * stage2/asm.S (console_cls): Write spaces to the entire screen diff --git a/stage2/disk_io.c b/stage2/disk_io.c index 920eb7bf8..4800638bb 100644 --- a/stage2/disk_io.c +++ b/stage2/disk_io.c @@ -148,6 +148,13 @@ rawread (int drive, int sector, int byte_offset, int byte_len, char *buf) buf_track = -1; } + /* Make sure that SECTOR is valid. */ + if (sector < 0 || sector >= buf_geom.total_sectors) + { + errnum = ERR_GEOM; + return 0; + } + /* Get first sector of track */ soff = sector % buf_geom.sectors; track = sector - soff; @@ -381,8 +388,9 @@ static void attempt_mount (void) { #ifndef STAGE1_5 - for (fsys_type = 0; fsys_type < NUM_FSYS - && (*(fsys_table[fsys_type].mount_func)) () != 1; fsys_type++); + for (fsys_type = 0; fsys_type < NUM_FSYS; fsys_type++) + if ((fsys_table[fsys_type].mount_func) ()) + break; if (fsys_type == NUM_FSYS && errnum == ERR_NONE) errnum = ERR_FSYS_MOUNT; diff --git a/stage2/fsys_reiserfs.c b/stage2/fsys_reiserfs.c index ef884ef83..63be9d826 100644 --- a/stage2/fsys_reiserfs.c +++ b/stage2/fsys_reiserfs.c @@ -587,7 +587,7 @@ reiserfs_mount (void) || ! devread (superblock, 0, sizeof (struct reiserfs_super_block), (char *) &super)) return 0; - + if (substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0 && substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) > 0) { @@ -601,7 +601,7 @@ reiserfs_mount (void) super.s_version = 0; } } - + /* check the version number. */ if (super.s_version > REISERFS_MAX_SUPPORTED_VERSION) return 0; @@ -612,7 +612,7 @@ reiserfs_mount (void) INFO->blocksize_shift = INFO->fullblocksize_shift - SECTOR_BITS; INFO->cached_slots = (FSYSREISER_CACHE_SIZE >> INFO->fullblocksize_shift) - 1; - + if (super.s_blocksize < FSYSREISER_MIN_BLOCKSIZE || super.s_blocksize > FSYSREISER_MAX_BLOCKSIZE || (SECTOR_SIZE << INFO->blocksize_shift) != super.s_blocksize) @@ -643,7 +643,7 @@ reiserfs_mount (void) printf ("root read_in: block=%d, depth=%d\n", super.s_root_block, INFO->tree_depth); #endif /* REISERDEBUG */ - + if (INFO->tree_depth >= MAX_HEIGHT) return 0; if (INFO->tree_depth == DISK_LEAF_NODE_LEVEL)