use filepath.Match instead of regex
This commit is contained in:
parent
5951d9b0ee
commit
e0322042c7
|
|
@ -26,7 +26,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -696,7 +695,7 @@ func HasFilepathPrefix(path, prefix string, prefixMatchOnly bool) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
for index := range prefixArray {
|
for index := range prefixArray {
|
||||||
m, err := regexp.MatchString(prefixArray[index], pathArray[index])
|
m, err := filepath.Match(prefixArray[index], pathArray[index])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ func Test_DetectFilesystemWhitelist(t *testing.T) {
|
||||||
{"/sys", false},
|
{"/sys", false},
|
||||||
{"/var/run", false},
|
{"/var/run", false},
|
||||||
{"/etc/mtab", false},
|
{"/etc/mtab", false},
|
||||||
|
{"/tmp/apt-key-gpghome", true},
|
||||||
}
|
}
|
||||||
actualWhitelist := whitelist
|
actualWhitelist := whitelist
|
||||||
sort.Slice(actualWhitelist, func(i, j int) bool {
|
sort.Slice(actualWhitelist, func(i, j int) bool {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue