aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Djupström via Toybox <toybox@lists.landley.net>2020-06-09 15:56:25 +0200
committerRob Landley <rob@landley.net>2020-06-09 15:26:51 -0500
commitee25b232b47c741712e3576bf992d64d7c82ceac (patch)
treec74605df3b712ca3b147a24fc3dfc20d6d3e2b9f
parent4182944d6d5d214de3310272e1d3f25320ed493c (diff)
downloadtoybox-ee25b232b47c741712e3576bf992d64d7c82ceac.tar.gz
tar: fix bugs with adding hardlinks to archive
-rw-r--r--toys/posix/tar.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/toys/posix/tar.c b/toys/posix/tar.c
index 77dd6fe9..b257a34f 100644
--- a/toys/posix/tar.c
+++ b/toys/posix/tar.c
@@ -246,7 +246,8 @@ static int add_to_tar(struct dirtree *node)
i = 1;
} else {
// first time we've seen it. Store as normal file, but remember it.
- if (!(TT.hlc&255)) TT.hlx = xrealloc(TT.hlx, TT.hlc+256);
+ if (!(TT.hlc&255))
+ TT.hlx = xrealloc(TT.hlx, sizeof(*TT.hlx)*(TT.hlc+256));
TT.hlx[TT.hlc].arg = xstrdup(hname);
TT.hlx[TT.hlc].ino = st->st_ino;
TT.hlx[TT.hlc].dev = st->st_dev;
@@ -270,7 +271,7 @@ static int add_to_tar(struct dirtree *node)
}
if (strlen(lnk) > sizeof(hdr.link)) write_longname(lnk, 'K');
strncpy(hdr.link, lnk, sizeof(hdr.link));
- if (i) free(lnk);
+ if (i==2) free(lnk);
} else if (S_ISREG(st->st_mode)) {
hdr.type = '0';
ITOO(hdr.size, st->st_size);