[PATCH] erofs-utils: bail out properly if erofs_iget_from_path(root) fails

Gao Xiang hsiangkao at linux.alibaba.com
Sat Sep 2 01:59:32 AEST 2023


Or "Segmentation fault" can happen if errors are passed into
erofs_igrab().

Fixes: 21d84349e79a ("erofs-utils: rearrange on-disk metadata")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/inode.c b/lib/inode.c
index 85eacab..a3a643f 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1228,10 +1228,11 @@ struct erofs_inode *erofs_mkfs_build_tree_from_path(const char *path)
 	LIST_HEAD(dirs);
 	struct erofs_inode *inode, *root, *parent;
 
-	root = erofs_igrab(erofs_iget_from_path(path, true));
+	root = erofs_iget_from_path(path, true);
 	if (IS_ERR(root))
 		return root;
 
+	(void)erofs_igrab(root);
 	root->i_parent = root;	/* rootdir mark */
 	root->subdirs_queued = 1;
 	list_add(&root->i_subdirs, &dirs);
-- 
2.24.4



More information about the Linux-erofs mailing list