diff options
author | Elliott Hughes <enh@google.com> | 2020-10-14 13:16:49 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-10-15 15:47:06 -0500 |
commit | 6a5b8bf6cb7a5f481c3bab6fb285d977851e4e2f (patch) | |
tree | 5e93ce36eef4c680cb005aa5f8afa33c0055f2e0 /lib | |
parent | 8eb9d6e0d3217bd0b1ffba73b3dfda1f79787845 (diff) | |
download | toybox-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.c | 4 |
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; |