From 55bea6e7a64b1134dc5cecdd4a63961cb3b720c4 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 14 May 2021 22:14:05 +0200 Subject: [PATCH] filter: Fix crash for '**' pattern --- changelog/unreleased/issue-3380 | 7 +++++++ internal/filter/filter.go | 5 +++++ internal/filter/filter_test.go | 1 + 3 files changed, 13 insertions(+) create mode 100644 changelog/unreleased/issue-3380 diff --git a/changelog/unreleased/issue-3380 b/changelog/unreleased/issue-3380 new file mode 100644 index 000000000..bf18cda48 --- /dev/null +++ b/changelog/unreleased/issue-3380 @@ -0,0 +1,7 @@ +Bugfix: Fix crash of `backup --exclude='**'` + +The exclude filter '**', which excludes all files, caused restic to crash. This +has been fixed. + +https://github.com/restic/restic/issues/3380 +https://github.com/restic/restic/pull/3393 diff --git a/internal/filter/filter.go b/internal/filter/filter.go index 1f6f04133..84aa82784 100644 --- a/internal/filter/filter.go +++ b/internal/filter/filter.go @@ -166,6 +166,11 @@ func match(patterns Pattern, strs []string) (matched bool, err error) { return true, nil } + // an empty pattern never matches a non-empty path + if len(patterns) == 0 { + return false, nil + } + if len(patterns) <= len(strs) { minOffset := 0 maxOffset := len(strs) - len(patterns) diff --git a/internal/filter/filter_test.go b/internal/filter/filter_test.go index ee7f05a32..30cee40db 100644 --- a/internal/filter/filter_test.go +++ b/internal/filter/filter_test.go @@ -23,6 +23,7 @@ var matchTests = []struct { {"*.go", "/foo/bar/test.go", true}, {"*.c", "/foo/bar/test.go", false}, {"*", "/foo/bar/test.go", true}, + {"**", "/foo/bar/test.go", true}, {"foo*", "/foo/bar/test.go", true}, {"bar*", "/foo/bar/test.go", true}, {"/bar*", "/foo/bar/test.go", false},