Skip to contentSkip to conversation

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

PATCH New Vansh Choudhary 1 participant 1 message Apr 20 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: restore path on erofs_rebuild_get_dentry() errors

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()")
---
 lib/rebuild.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/rebuild.c +6 -2
index 74bbeda..14013cf 100644
@@ -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))
Signature · 1 line
2.43.0