add handling of a '.' commondir and bounds checking to mount_linux

Signed-off-by: Craig Ingram <Cjingram@google.com>
This commit is contained in:
Craig Ingram 2023-05-30 20:55:13 +00:00
parent 4b7145cfd3
commit d2605de734
2 changed files with 11 additions and 1 deletions

View File

@ -274,13 +274,16 @@ func compactLowerdirOption(opts []string) (string, []string) {
// in order to avoid to get snapshots/x, should be back to parent dir.
// however, there is assumption that the common dir is ${root}/io.containerd.v1.overlayfs/snapshots.
commondir = path.Dir(commondir)
if commondir == "/" {
if commondir == "/" || commondir == "." {
return "", opts
}
commondir = commondir + "/"
newdirs := make([]string, 0, len(dirs))
for _, dir := range dirs {
if len(dir) <= len(commondir) {
return "", opts
}
newdirs = append(newdirs, dir[len(commondir):])
}

View File

@ -84,6 +84,13 @@ func TestCompactLowerdirOption(t *testing.T) {
"",
[]string{"lowerdir=/snapshots/1/fs:/other_snapshots/1/fs"},
},
// if common dir is .
{
[]string{"lowerdir=a:aaa"},
"",
[]string{"lowerdir=a:aaa"},
},
}
for i, tc := range tcases {