From d2605de734e7374ad753b5f34168da7b1803057e Mon Sep 17 00:00:00 2001 From: Craig Ingram Date: Tue, 30 May 2023 20:55:13 +0000 Subject: [PATCH] add handling of a '.' commondir and bounds checking to mount_linux Signed-off-by: Craig Ingram --- mount/mount_linux.go | 5 ++++- mount/mount_linux_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mount/mount_linux.go b/mount/mount_linux.go index 4183333db..736bb4cbb 100644 --- a/mount/mount_linux.go +++ b/mount/mount_linux.go @@ -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):]) } diff --git a/mount/mount_linux_test.go b/mount/mount_linux_test.go index 2a3bac990..037c246ea 100644 --- a/mount/mount_linux_test.go +++ b/mount/mount_linux_test.go @@ -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 {