summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-store/util/fs.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2021-12-20 09:35:32 +0000
committerLibravatar GitHub <noreply@github.com>2021-12-20 10:35:32 +0100
commit635ad2a42f10a5b24f08021782b71b4cf8326e19 (patch)
tree3221d2c4526b5214c9a9b9d33343d48b2e9c9649 /vendor/codeberg.org/gruf/go-store/util/fs.go
parentLog when listening (#350) (diff)
downloadgotosocial-635ad2a42f10a5b24f08021782b71b4cf8326e19.tar.xz
Update codeberg.org/gruf libraries and fix go-store issue (#347)
* update codeberg.org/gruf/ libraries Signed-off-by: kim <grufwub@gmail.com> * another update Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-store/util/fs.go')
-rw-r--r--vendor/codeberg.org/gruf/go-store/util/fs.go20
1 files changed, 14 insertions, 6 deletions
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