From 8a8e50e6d7baf99ebe02e6ca04d9d842addcd36c Mon Sep 17 00:00:00 2001 From: Alexey Lunev Date: Fri, 8 Nov 2024 03:49:57 +0300 Subject: [PATCH 1/2] fsverity_test.go: fix nil pointer dereference, fix test fail Signed-off-by: Alexey Lunev --- internal/fsverity/fsverity_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/fsverity/fsverity_test.go b/internal/fsverity/fsverity_test.go index 1bd122ba57c9..514af07fb950 100644 --- a/internal/fsverity/fsverity_test.go +++ b/internal/fsverity/fsverity_test.go @@ -123,8 +123,8 @@ func TestIsEnabled(t *testing.T) { t.Errorf("fsverity Enable failed: %s", err.Error()) } - if enabled, err := IsEnabled(verityFile); !enabled || err != nil { - t.Errorf("expected fsverity to be enabled on file, received enabled: %t; error: %s", enabled, err.Error()) + if enabled, err := IsEnabled(verityFile); !enabled && err != nil { + t.Errorf("expected fsverity to be enabled on file, received enabled: %t; error: %v", enabled, err) } } From f9537ae126fc2be685cc32d5c98b4189a72e02e9 Mon Sep 17 00:00:00 2001 From: Alexey Lunev Date: Fri, 8 Nov 2024 03:50:44 +0300 Subject: [PATCH 2/2] fsverity_test.go: fix major/minor device number resolving Signed-off-by: Alexey Lunev --- internal/fsverity/fsverity_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/fsverity/fsverity_test.go b/internal/fsverity/fsverity_test.go index 514af07fb950..87c685d041cb 100644 --- a/internal/fsverity/fsverity_test.go +++ b/internal/fsverity/fsverity_test.go @@ -29,6 +29,7 @@ import ( "testing" "github.com/containerd/containerd/v2/pkg/testutil" + "golang.org/x/sys/unix" ) type superblockROFeatures struct { @@ -143,8 +144,7 @@ func resolveDevicePath(path string) (_ string, e error) { } // resolve to device path - maj := (stat.Dev >> 8) & 0xff - min := stat.Dev & 0xff + major, minor := unix.Major(stat.Dev), unix.Minor(stat.Dev) m, err := os.Open("/proc/self/mountinfo") if err != nil { @@ -162,7 +162,7 @@ func resolveDevicePath(path string) (_ string, e error) { scanner := bufio.NewScanner(m) var entry string - sub := fmt.Sprintf("%d:%d", maj, min) + sub := fmt.Sprintf("%d:%d", major, minor) for scanner.Scan() { if strings.Contains(scanner.Text(), sub) { entry = scanner.Text()