erofs-utils: bail out properly if erofs_iget_from_path(root) fails
authorGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 1 Sep 2023 15:59:32 +0000 (23:59 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 1 Sep 2023 17:58:02 +0000 (01:58 +0800)
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@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230901155932.105830-1-hsiangkao@linux.alibaba.com
lib/inode.c

index 85eacabd8349af79a0809e430e289f177624031d..a3a643fad8f057f036dee058b35493229db34bcc 100644 (file)
@@ -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);