Skip to content

Commit

Permalink
Merge pull request containerd#10972 from xbt573/main
Browse files Browse the repository at this point in the history
fsverity_test.go: fix nil pointer derefence, fix test fail, fix minor/major device numbers resolving
  • Loading branch information
samuelkarp authored Nov 8, 2024
2 parents ebda6bc + f9537ae commit 0be529a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/fsverity/fsverity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"testing"

"github.com/containerd/containerd/v2/pkg/testutil"
"golang.org/x/sys/unix"
)

type superblockROFeatures struct {
Expand Down Expand Up @@ -123,8 +124,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)
}
}

Expand All @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit 0be529a

Please sign in to comment.