vendor update

This commit is contained in:
Nathan Gieseker
2019-06-17 21:33:55 -07:00
parent 13fbc4afdf
commit e8c953999e
900 changed files with 36135 additions and 265442 deletions

View File

@ -87,7 +87,7 @@ func OpenRoot(path string) (*os.File, error) {
func ntRelativePath(path string) ([]uint16, error) {
path = filepath.Clean(path)
if strings.Contains(":", path) {
if strings.Contains(path, ":") {
// Since alternate data streams must follow the file they
// are attached to, finding one here (out of order) is invalid.
return nil, errors.New("path contains invalid character `:`")

View File

@ -1,125 +0,0 @@
// +build admin
package safefile
import (
"os"
"path/filepath"
"syscall"
"testing"
)
func TestOpenRelative(t *testing.T) {
badroot, err := tempRoot()
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(badroot.Name())
defer badroot.Close()
root, err := tempRoot()
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root.Name())
defer root.Close()
// Create a file
f, err := OpenRelative("foo", root, 0, syscall.FILE_SHARE_READ, FILE_CREATE, 0)
if err != nil {
t.Fatal(err)
}
f.Close()
// Create a directory
err = MkdirRelative("dir", root)
if err != nil {
t.Fatal(err)
}
// Create a file in the bad root
f, err = os.Create(filepath.Join(badroot.Name(), "badfile"))
if err != nil {
t.Fatal(err)
}
f.Close()
// Create a directory symlink to the bad root
err = os.Symlink(badroot.Name(), filepath.Join(root.Name(), "dsymlink"))
if err != nil {
t.Fatal(err)
}
// Create a file symlink to the bad file
err = os.Symlink(filepath.Join(badroot.Name(), "badfile"), filepath.Join(root.Name(), "symlink"))
if err != nil {
t.Fatal(err)
}
// Make sure opens cannot happen through the symlink
f, err = OpenRelative("dsymlink/foo", root, 0, syscall.FILE_SHARE_READ, FILE_CREATE, 0)
if err == nil {
f.Close()
t.Fatal("created file in wrong tree!")
}
t.Log(err)
// Check again using EnsureNotReparsePointRelative
err = EnsureNotReparsePointRelative("dsymlink", root)
if err == nil {
t.Fatal("reparse check should have failed")
}
t.Log(err)
// Make sure links work
err = LinkRelative("foo", root, "hardlink", root)
if err != nil {
t.Fatal(err)
}
// Even inside directories
err = LinkRelative("foo", root, "dir/bar", root)
if err != nil {
t.Fatal(err)
}
// Make sure links cannot happen through the symlink
err = LinkRelative("foo", root, "dsymlink/hardlink", root)
if err == nil {
f.Close()
t.Fatal("created link in wrong tree!")
}
t.Log(err)
// In either direction
err = LinkRelative("dsymlink/badfile", root, "bar", root)
if err == nil {
f.Close()
t.Fatal("created link in wrong tree!")
}
t.Log(err)
// Make sure remove cannot happen through the symlink
err = RemoveRelative("symlink/badfile", root)
if err == nil {
t.Fatal("remove in wrong tree!")
}
// Remove the symlink
err = RemoveAllRelative("symlink", root)
if err != nil {
t.Fatal(err)
}
// Make sure it's not possible to escape with .. (NT doesn't support .. at the kernel level)
f, err = OpenRelative("..", root, syscall.GENERIC_READ, syscall.FILE_SHARE_READ, FILE_OPEN, 0)
if err == nil {
t.Fatal("escaped the directory")
}
t.Log(err)
// Should not have touched the other directory
if _, err = os.Lstat(filepath.Join(badroot.Name(), "badfile")); err != nil {
t.Fatal(err)
}
}

View File

@ -1,53 +0,0 @@
package safefile
import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"
winio "github.com/Microsoft/go-winio"
)
func tempRoot() (*os.File, error) {
name, err := ioutil.TempDir("", "hcsshim-test")
if err != nil {
return nil, err
}
f, err := OpenRoot(name)
if err != nil {
os.Remove(name)
return nil, err
}
return f, nil
}
func TestRemoveRelativeReadOnly(t *testing.T) {
root, err := tempRoot()
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root.Name())
defer root.Close()
p := filepath.Join(root.Name(), "foo")
f, err := os.Create(p)
if err != nil {
t.Fatal(err)
}
defer f.Close()
bi := winio.FileBasicInfo{}
bi.FileAttributes = syscall.FILE_ATTRIBUTE_READONLY
err = winio.SetFileBasicInfo(f, &bi)
if err != nil {
t.Fatal(err)
}
f.Close()
err = RemoveRelative("foo", root)
if err != nil {
t.Fatal(err)
}
}