[PATCH] erofs-utils: lib: restore path on erofs_rebuild_get_dentry() errors

Vansh Choudhary ch at vnsh.in
Tue Apr 21 05:16:43 AEST 2026


erofs_rebuild_get_dentry() temporarily writes '\0' over each '/'
in the caller's path to NUL-terminate segments, but two error
returns skip the restoration and leave the path truncated.

Restore the slash before those returns.

Fixes: 73e321a0fb3b ("erofs-utils: lib: consolidate erofs_rebuild_get_dentry()")
Signed-off-by: Vansh Choudhary <ch at vnsh.in>
---
 lib/rebuild.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/rebuild.c b/lib/rebuild.c
index 74bbeda..14013cf 100644
--- a/lib/rebuild.c
+++ b/lib/rebuild.c
@@ -123,8 +123,10 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,
 			d = erofs_d_lookup(pwd, s);
 			if (d) {
 				if (d->type != EROFS_FT_DIR) {
-					if (slash)
+					if (slash) {
+						*slash = '/';
 						return ERR_PTR(-ENOTDIR);
+					}
 				} else if (to_head) {
 					list_del(&d->d_child);
 					list_add(&d->d_child, &pwd->i_subdirs);
@@ -132,8 +134,10 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,
 				pwd = d->inode;
 			} else if (slash) {
 				d = erofs_rebuild_mkdir(pwd, s);
-				if (IS_ERR(d))
+				if (IS_ERR(d)) {
+					*slash = '/';
 					return d;
+				}
 			} else {
 				d = erofs_d_alloc(pwd, s);
 				if (IS_ERR(d))
-- 
2.43.0



More information about the Linux-erofs mailing list