From 813bbb25a24ebba5177da18be413ea742efe5a8a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 22 Jun 1999 03:17:45 +0000 Subject: [PATCH] ChangeLog, dir_iterate.c: dir_iterate.c (ext2fs_process_dir_block): Check for corrupted directory entry before calling the callback function. This should prevent some core dumps of insufficiently paranoid callback functions. ChangeLog, unix.c: unix.c (main): Add missing space in the disk write-protected message. --- e2fsck/ChangeLog | 5 +++++ e2fsck/unix.c | 5 +++-- lib/ext2fs/ChangeLog | 7 +++++++ lib/ext2fs/dir_iterate.c | 12 ++++++------ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 3752671..5894054 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,8 @@ +1999-06-21 + + * unix.c (main): Add missing space in the disk write-protected + message. + 1999-05-22 * problem.c, problem.h (PR_0_INODE_COUNT_WRONG): Add new problem diff --git a/e2fsck/unix.c b/e2fsck/unix.c index fb67f6a..e25bbf3 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -255,7 +255,8 @@ static void reserve_stdio_fds(NOARGS) if (fd > 2) break; if (fd < 0) { - fprintf(stderr, "ERROR: Couldn't open /dev/null (%s)\n", + fprintf(stderr, "ERROR: Couldn't open " + "/dev/null (%s)\n", strerror(errno)); break; } @@ -556,7 +557,7 @@ restart: printf("Possibly non-existent or swap device?\n"); #ifdef EROFS else if (retval == EROFS) - printf("Disk write-protected; use the -n option" + printf("Disk write-protected; use the -n option " "to do a read-only\n" "check of the device.\n"); #endif diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 8b2e372..9fc24e9 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,10 @@ +1999-06-21 + + * dir_iterate.c (ext2fs_process_dir_block): Check for corrupted + directory entry before calling the callback function. + This should prevent some core dumps of insufficiently + paranoid callback functions. + 1999-05-29 * ext2fs.h: Add feature definition for AFS IMAGIC inodes. diff --git a/lib/ext2fs/dir_iterate.c b/lib/ext2fs/dir_iterate.c index 10a136a..3fecf23 100644 --- a/lib/ext2fs/dir_iterate.c +++ b/lib/ext2fs/dir_iterate.c @@ -98,6 +98,12 @@ int ext2fs_process_dir_block(ext2_filsys fs, while (offset < fs->blocksize) { dirent = (struct ext2_dir_entry *) (ctx->buf + offset); + if (((offset + dirent->rec_len) > fs->blocksize) || + (dirent->rec_len < 8) || + (((dirent->name_len & 0xFF)+8) > dirent->rec_len)) { + ctx->errcode = EXT2_ET_DIR_CORRUPTED; + return BLOCK_ABORT; + } if (!dirent->inode && !(ctx->flags & DIRENT_FLAG_INCLUDE_EMPTY)) goto next; @@ -120,12 +126,6 @@ int ext2fs_process_dir_block(ext2_filsys fs, break; } next: - if (((offset + dirent->rec_len) > fs->blocksize) || - (dirent->rec_len < 8) || - (((dirent->name_len & 0xFF)+8) > dirent->rec_len)) { - ctx->errcode = EXT2_ET_DIR_CORRUPTED; - return BLOCK_ABORT; - } offset += dirent->rec_len; } -- 1.8.3.1