mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
runsc: do not include sub target if it is not started with '/'.
PiperOrigin-RevId: 200274828 Change-Id: I956703217df08d8650a881479b7ade8f9f119912
This commit is contained in:
@@ -445,6 +445,9 @@ func addSubmountOverlay(ctx context.Context, inode *fs.Inode, submounts []string
|
||||
// children of the given root. The returned paths are relative to the root.
|
||||
func subtargets(root string, mnts []specs.Mount) []string {
|
||||
r := filepath.Clean(root)
|
||||
if len(r) > 0 && r[len(r)-1] != '/' {
|
||||
r += "/"
|
||||
}
|
||||
var targets []string
|
||||
for _, mnt := range mnts {
|
||||
t := filepath.Clean(mnt.Destination)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package boot
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -150,6 +151,12 @@ func TestCreateMountNamespace(t *testing.T) {
|
||||
DisableSeccomp: true,
|
||||
}
|
||||
|
||||
testFile, err := ioutil.TempFile(os.TempDir(), "create-mount-namespace-")
|
||||
if err != nil {
|
||||
t.Fatalf("ioutil.TempFile() failed, err: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(testFile.Name())
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
// Spec that will be used to create the mount manager. Note
|
||||
@@ -202,7 +209,7 @@ func TestCreateMountNamespace(t *testing.T) {
|
||||
expectedPaths: []string{"/some/very/very/deep/path", "/proc", "/dev", "/sys"},
|
||||
},
|
||||
{
|
||||
// Mounts are nested inside eachother.
|
||||
// Mounts are nested inside each other.
|
||||
name: "nested mounts",
|
||||
spec: specs.Spec{
|
||||
Root: &specs.Root{
|
||||
@@ -218,6 +225,16 @@ func TestCreateMountNamespace(t *testing.T) {
|
||||
Destination: "/foo",
|
||||
Type: "tmpfs",
|
||||
},
|
||||
{
|
||||
Destination: "/foo/qux",
|
||||
Source: testFile.Name(),
|
||||
Type: "bind",
|
||||
},
|
||||
{
|
||||
// File mounts with the same prefix.
|
||||
Destination: "/foo/qux-quz",
|
||||
Type: "tmpfs",
|
||||
},
|
||||
{
|
||||
Destination: "/foo/bar",
|
||||
Type: "tmpfs",
|
||||
@@ -233,7 +250,8 @@ func TestCreateMountNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedPaths: []string{"/foo", "/foo/bar", "/foo/bar/baz", "/foo/some/very/very/deep/path", "/proc", "/dev", "/sys"},
|
||||
expectedPaths: []string{"/foo", "/foo/bar", "/foo/bar/baz", "/foo/qux",
|
||||
"/foo/qux-quz", "/foo/some/very/very/deep/path", "/proc", "/dev", "/sys"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user