aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-10-03 00:26:12 -0500
committerRob Landley <rob@landley.net>2020-10-03 00:26:12 -0500
commit424632aaa30e85e069678da8c413a35c4d321cf6 (patch)
tree874843c18ee79ce1ae9de6c326edcd1820d64a1e
parentf570a02c6c544b9d8f277c43506cdde92d947d73 (diff)
downloadtoybox-424632aaa30e85e069678da8c413a35c4d321cf6.tar.gz
Non-recursive dirtree_path() needs to return start of allocation
when passed in extra allocation length or else free() gets very unhappy.
-rw-r--r--lib/dirtree.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index 02f4b887..9712ee14 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -85,12 +85,13 @@ char *dirtree_path(struct dirtree *node, int *plen)
{
struct dirtree *nn;
char *path;
- int len = plen ? *plen : 0;
+ int ll, len;
+ ll = len = plen ? *plen : 0;
for (nn = node; nn; nn = nn->parent) if (*nn->name) len += strlen(nn->name)+1;
if (plen) *plen = len;
if (!len) return 0;
- path = xmalloc(len)+len;
+ path = xmalloc(len)+len-ll;
for (nn = node; nn; nn = nn->parent) if ((len = strlen(nn->name))) {
*--path = '/'*(nn != node);
memcpy(path -= len, nn->name, len);