Add a `\0` placeholder before `path`.

Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Reported-by: Nikolay Gorbatov <[email protected]>
Closes: https://github.com/erofs/erofs-utils/issues/29
Signed-off-by: Gao Xiang <[email protected]>
---
 lib/tar.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/tar.c b/lib/tar.c
index c93f2c6..139d1c5 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -694,7 +694,7 @@ int tarerofs_parse_tar(struct erofs_importer *im, struct 
erofs_tarfile *tar)
        struct erofs_sb_info *sbi = im->sbi;
        struct erofs_inode *root = im->root;
        bool whout, opq, e = false;
-       char path[PATH_MAX];
+       char _path[PATH_MAX + 1], *path = _path + 1;
        struct stat st;
        mode_t mode;
        erofs_off_t tar_offset, dataoff;
@@ -702,8 +702,8 @@ int tarerofs_parse_tar(struct erofs_importer *im, struct 
erofs_tarfile *tar)
        struct tar_header *th;
        struct erofs_dentry *d;
        struct erofs_inode *inode;
-       unsigned int j, csum, cksum;
-       int ckksum, ret, rem;
+       unsigned int csum, cksum;
+       int ckksum, ret, rem, j;
 
        root->dev = tar->dev;
        if (eh.path)
@@ -817,6 +817,7 @@ out_eot:
                        path[0] = '.';
                        path[1] = '\0';
                } else {
+                       *_path = '\0';
                        while (path[j - 1] == '/')
                                path[--j] = '\0';
                }
-- 
2.43.5


Reply via email to