diff --git a/client/allocrunner/taskrunner/getter/util.go b/client/allocrunner/taskrunner/getter/util.go index 4e7f4ca1a..919008f31 100644 --- a/client/allocrunner/taskrunner/getter/util.go +++ b/client/allocrunner/taskrunner/getter/util.go @@ -303,6 +303,10 @@ func isPathWithin(rootPath, toCheckPath string) (bool, error) { checkStat, err := os.Stat(toCheckPath[0:len(rootPath)]) if err != nil { + if errors.Is(err, os.ErrNotExist) { + return false, nil + } + return false, err } diff --git a/client/allocrunner/taskrunner/getter/util_test.go b/client/allocrunner/taskrunner/getter/util_test.go index 925770eef..07ee95570 100644 --- a/client/allocrunner/taskrunner/getter/util_test.go +++ b/client/allocrunner/taskrunner/getter/util_test.go @@ -286,4 +286,15 @@ func TestUtil_isPathWithin(t *testing.T) { must.ErrorContains(t, err, "no such file or directory") must.False(t, result) }) + + t.Run("when path not within root but shorter", func(t *testing.T) { + root, err := os.MkdirTemp(tdir, "testing-path-XXX") + must.NoError(t, err) + check, err := os.MkdirTemp(tdir, "testing-path-XXXX") + must.NoError(t, err) + result, err := isPathWithin(root, check) + + must.NoError(t, err) + must.False(t, result) + }) }