[Toybox] [PATCH 1/2] tar: don't recurse into excluded directories

William Djupström william at deepztream.com
Tue Jun 9 06:56:24 PDT 2020


---
 toys/posix/tar.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/toys/posix/tar.c b/toys/posix/tar.c
index 77dd6fe9..8706ac30 100644
--- a/toys/posix/tar.c
+++ b/toys/posix/tar.c
@@ -179,7 +179,7 @@ static int add_to_tar(struct dirtree *node)
   struct tar_hdr hdr;
   struct passwd *pw = pw;
   struct group *gr = gr;
-  int i, fd =-1;
+  int i, fd =-1, flags = 0;
   char *name, *lnk, *hname;
 
   if (!dirtree_notdotdot(node)) return 0;
@@ -193,7 +193,7 @@ static int add_to_tar(struct dirtree *node)
 
   // exclusion defaults to --no-anchored and --wildcards-match-slash
   for (lnk = name; *lnk;) {
-    if (filter(TT.excl, lnk)) goto done;
+    if (filter(TT.excl, lnk)) goto done_norecurse;
     while (*lnk && *lnk!='/') lnk++;
     while (*lnk=='/') lnk++;
   }
@@ -372,9 +372,12 @@ static int add_to_tar(struct dirtree *node)
     close(fd);
   }
 done:
+  flags = (DIRTREE_RECURSE|(FLAG(h)?DIRTREE_SYMFOLLOW:0))*!FLAG(no_recursion);
+
+done_norecurse:
   free(name);
 
-  return (DIRTREE_RECURSE|(FLAG(h)?DIRTREE_SYMFOLLOW:0))*!FLAG(no_recursion);
+  return flags;
 }
 
 static void wsettime(char *s, long long sec)
-- 
2.26.2



More information about the Toybox mailing list