From 635ad2a42f10a5b24f08021782b71b4cf8326e19 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Mon, 20 Dec 2021 09:35:32 +0000 Subject: Update codeberg.org/gruf libraries and fix go-store issue (#347) * update codeberg.org/gruf/ libraries Signed-off-by: kim * another update Signed-off-by: kim --- vendor/codeberg.org/gruf/go-store/util/fs.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'vendor/codeberg.org/gruf/go-store/util/fs.go') diff --git a/vendor/codeberg.org/gruf/go-store/util/fs.go b/vendor/codeberg.org/gruf/go-store/util/fs.go index fa6a9d2c4..93b37a261 100644 --- a/vendor/codeberg.org/gruf/go-store/util/fs.go +++ b/vendor/codeberg.org/gruf/go-store/util/fs.go @@ -9,14 +9,22 @@ import ( "codeberg.org/gruf/go-fastpath" ) -var dotdot = "../" +// IsDirTraversal will check if rootPlusPath is a dir traversal outside of root, +// assuming that both are cleaned and that rootPlusPath is path.Join(root, somePath) +func IsDirTraversal(root string, rootPlusPath string) bool { + switch { + // Root is $PWD, check for traversal out of + case root == ".": + return strings.HasPrefix(rootPlusPath, "../") -// CountDotdots returns the number of "dot-dots" (../) in a cleaned filesystem path -func CountDotdots(path string) int { - if !strings.HasSuffix(path, dotdot) { - return 0 + // The path MUST be prefixed by root + case !strings.HasPrefix(rootPlusPath, root): + return true + + // In all other cases, check not equal + default: + return len(root) == len(rootPlusPath) } - return strings.Count(path, dotdot) } // WalkDir traverses the dir tree of the supplied path, performing the supplied walkFn on each entry -- cgit v1.2.3