[PATCH 2/4] erofs-utils: lib: fix recursive erofs_iterate_dir()

Jingbo Xu jefflexu at linux.alibaba.com
Tue Jul 18 15:20:59 AEST 2023


ctx->dir may have changed when ctx is reused along erofs_iterate_dir()
recursion.

Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
 lib/dir.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/dir.c b/lib/dir.c
index abbf27a..6758b8d 100644
--- a/lib/dir.c
+++ b/lib/dir.c
@@ -9,6 +9,7 @@ static int traverse_dirents(struct erofs_dir_context *ctx,
 			    unsigned int next_nameoff, unsigned int maxsize,
 			    bool fsck)
 {
+	struct erofs_inode *dir = ctx->dir;
 	struct erofs_dirent *de = dentry_blk;
 	const struct erofs_dirent *end = dentry_blk + next_nameoff;
 	const char *prev_name = NULL;
@@ -76,7 +77,7 @@ static int traverse_dirents(struct erofs_dir_context *ctx,
 					goto out;
 				}
 				ctx->flags |= EROFS_READDIR_DOTDOT_FOUND;
-				if (sbi.root_nid == ctx->dir->nid) {
+				if (sbi.root_nid == dir->nid) {
 					ctx->pnid = sbi.root_nid;
 					ctx->flags |= EROFS_READDIR_VALID_PNID;
 				}
@@ -95,7 +96,7 @@ static int traverse_dirents(struct erofs_dir_context *ctx,
 				}
 
 				ctx->flags |= EROFS_READDIR_DOT_FOUND;
-				if (fsck && ctx->de_nid != ctx->dir->nid) {
+				if (fsck && ctx->de_nid != dir->nid) {
 					errmsg = "corrupted `.' dirent";
 					goto out;
 				}
@@ -115,7 +116,7 @@ static int traverse_dirents(struct erofs_dir_context *ctx,
 out:
 	if (ret && !silent)
 		erofs_err("%s @ nid %llu, lblk %u, index %lu",
-			  errmsg, ctx->dir->nid | 0ULL, lblk,
+			  errmsg, dir->nid | 0ULL, lblk,
 			  (de - (struct erofs_dirent *)dentry_blk) | 0UL);
 	return ret;
 }
-- 
2.19.1.6.gb485710b



More information about the Linux-erofs mailing list