From 24133d5e23d7e271cd788a8250975d9ee83b5717 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 6 Apr 2023 10:48:05 -0500 Subject: [PATCH] The non-anchored --wildcards logic broke full-string matching. (It matched after every / but when there was one it didn't check start of string. Oops.) --- tests/tar.test | 5 +++++ toys/posix/tar.c | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/tar.test b/tests/tar.test index fb26991f..e6487bd7 100755 --- a/tests/tar.test +++ b/tests/tar.test @@ -383,6 +383,7 @@ testing 'without -P' "$TAR --no-recursion -C / /// .. 2>/dev/null | SUM 3" \ # Wildcards: --exclude, include (create/extract * cmdline/recursive) # --anchored, --wildcards, --wildcards-match-slash +# --no-* versions of each. Span coverage, switching on/off... #pattern a.c # abcd dabc a/c da/c @@ -413,6 +414,10 @@ touch sub2/{ephebe,klatch,djelibeybi} testing 'tsort' '$TAR -c sub2 --sort=name | tar t' \ 'sub2/\nsub2/djelibeybi\nsub2/ephebe\nsub2/klatch\n' '' '' +touch file +testing './file bug' 'tar c ./file > tar.tar && tar t ./file < tar.tar' \ + './file\n' '' '' + if false then # Sequencing issues that leak implementation details out the interface diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 977ccf0f..5af32db8 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -194,7 +194,7 @@ static struct double_list *filter(struct double_list *lst, char *name) { struct double_list *end = lst; long long flags = toys.optflags; - char *ss, *last; + char *ss; if (!lst || !*name) return 0; @@ -211,13 +211,11 @@ static struct double_list *filter(struct double_list *lst, char *name) // The +1 instead of ++ is in case of conseutive slashes do { - for (ss = last = name; *ss; ss++) { + if (do_filter(lst->data, name, flags)) return lst; + if (!(flags & FLAG_anchored)) for (ss = name; *ss; ss++) { if (*ss!='/' || !ss[1]) continue; - if (!(flags & FLAG_anchored)) { - if (do_filter(lst->data, ss+1, flags)) return lst; - } else last = ss+1; + if (do_filter(lst->data, ss+1, flags)) return lst; } - if (do_filter(lst->data, last, flags)) return lst; } while (end != (lst = lst->next)); return 0; -- 2.39.2