From 0d0f4a3944df0a33f0fafdc854bb737b069d5974 Mon Sep 17 00:00:00 2001 From: Niu Yawei Date: Thu, 5 Sep 2013 09:03:50 -0400 Subject: [PATCH] LU-3838 lfsck: various defects in lfsck - In lfsck_get_fid(), sizeof(buf) should be passed as buffer length, but not sizeof(*buf); - In lfsck_mds_dirs(), we should follow into directory if the directory doesn't contain self fid; - In ext2fs_attr_ibody_get(), returns EXT2_ET_EA_TOO_BIG only when the buffer isn't large enough; - In ext2fs_attr_ibody_get(), do type cast before operating on pointer! Signed-off-by: Niu Yawei Change-Id: I8ba4139fcc51b23bfa33c82c71f9b69b2b033a37 --- e2fsck/lfsck_common.c | 2 +- e2fsck/pass6.c | 3 ++- lib/ext2fs/ext_attr.c | 13 +++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/e2fsck/lfsck_common.c b/e2fsck/lfsck_common.c index 9819069..4f427ae 100644 --- a/e2fsck/lfsck_common.c +++ b/e2fsck/lfsck_common.c @@ -404,7 +404,7 @@ int lfsck_get_fid(ext2_filsys fs, ino_t ino, struct lu_fid *fid) return rc; } rc = ext2fs_attr_get(fs, inode, EXT2_ATTR_INDEX_TRUSTED, - LUSTRE_XATTR_MDT_LMA, buf, sizeof(*buf), &size); + LUSTRE_XATTR_MDT_LMA, buf, sizeof(buf), &size); if (rc) { if (rc != EXT2_ET_EA_NAME_NOT_FOUND && rc != EXT2_ET_EA_BAD_MAGIC) { diff --git a/e2fsck/pass6.c b/e2fsck/pass6.c index 7839bdd..df5b9ba 100644 --- a/e2fsck/pass6.c +++ b/e2fsck/pass6.c @@ -698,7 +698,7 @@ static int lfsck_mds_dirs(ext2_ino_t dir, int entry, rc = lfsck_get_fid(lctx->ctx->fs, dirent->inode, &mds_dirent.mds_fid); if (rc != 0) - return 0; + goto follow_on; DEBUG(lctx->ctx, "MDT: dirfid "DFID" child "DFID" file %.*s\n", PFID(&mds_dirent.mds_dirfid), PFID(&mds_dirent.mds_fid), @@ -725,6 +725,7 @@ static int lfsck_mds_dirs(ext2_ino_t dir, int entry, return DIRENT_ABORT; } } +follow_on: if (file_type == EXT2_FT_DIR) { lctx2 = *lctx; lctx2.dot = dirent->inode; diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index cedc2a2..852fe79 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -756,12 +756,12 @@ static errcode_t ext2fs_attr_block_get(ext2_filsys fs, struct ext2_inode *inode, if (easize) *easize = entry->e_value_size; if (buffer) { - error = EXT2_ET_EA_TOO_BIG; - if (entry->e_value_size > buffer_size) + if (entry->e_value_size > buffer_size) { + error = EXT2_ET_EA_TOO_BIG; goto cleanup; + } memcpy(buffer, block_buf + entry->e_value_offs, entry->e_value_size); - error = 0; } cleanup: @@ -809,10 +809,11 @@ static errcode_t ext2fs_attr_ibody_get(ext2_filsys fs, if (easize) *easize = entry->e_value_size; if (buffer) { - error = EXT2_ET_EA_TOO_BIG; - if (entry->e_value_size > buffer_size) + if (entry->e_value_size > buffer_size) { + error = EXT2_ET_EA_TOO_BIG; goto cleanup; - memcpy(buffer, &IHDR(inode)->h_first_entry[0] + + } + memcpy(buffer, (void *)&IHDR(inode)->h_first_entry[0] + entry->e_value_offs, entry->e_value_size); } -- 1.8.3.1