aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-10-14 13:16:49 -0700
committerRob Landley <rob@landley.net>2020-10-15 15:47:06 -0500
commit6a5b8bf6cb7a5f481c3bab6fb285d977851e4e2f (patch)
tree5e93ce36eef4c680cb005aa5f8afa33c0055f2e0 /lib
parent8eb9d6e0d3217bd0b1ffba73b3dfda1f79787845 (diff)
downloadtoybox-6a5b8bf6cb7a5f481c3bab6fb285d977851e4e2f.tar.gz
dirtree_path: always honor size request.
tar asks dirtree_path() to reserve space for a trailing '/', but recent changes broke that for the case that was resolving to just a strdup(). Caught by `export ASAN=1` and `make test_tar`.
Diffstat (limited to 'lib')
-rw-r--r--lib/dirtree.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index cc5d0545..736c2db5 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -87,8 +87,10 @@ char *dirtree_path(struct dirtree *node, int *plen)
char *path;
int ii, ll, len;
- if (!node->parent) return xstrdup(node->name);
ll = len = plen ? *plen : 0;
+ if (!node->parent) {
+ return strcpy(path = xzalloc(strlen(node->name)+ll+1), node->name);
+ }
for (nn = node; nn; nn = nn->parent)
if ((ii = strlen(nn->name))) len += ii+1-(nn->name[ii-1]=='/');
if (plen) *plen = len;