Skip to content

Commit

Permalink
Fix HasSecureKernelVersion and extend tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
NullHypothesis committed Oct 12, 2024
1 parent 3ffd242 commit b9d58ad
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/system/system_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func HasSecureKernelVersion() bool {
var uname syscall.Utsname
if err := syscall.Uname(&uname); err == nil {
if err := syscall.Uname(&uname); err != nil {
log.Printf("Error calling uname system call: %v", err)
return false
}
Expand All @@ -27,7 +27,7 @@ func hasSecureKernelVersion(uname syscall.Utsname) bool {
version[offset] = digit
digit = 0
offset++
if offset > len(version) {
if offset >= len(version) {
break
}
}
Expand Down
44 changes: 43 additions & 1 deletion internal/system/system_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,54 @@ func TestHasSecureKernelVersion(t *testing.T) {
want bool
}{
{
name: "kernel version is too low",
name: "patch version too low",
uname: syscall.Utsname{
Release: [65]int8{'5', '.', '1', '7', '.', '1', '1'},
},
want: false,
},
{
name: "minor version too low",
uname: syscall.Utsname{
Release: [65]int8{'5', '.', '1', '6', '.', '1', '2'},
},
want: false,
},
{
name: "major version too low",
uname: syscall.Utsname{
Release: [65]int8{'4', '.', '1', '7', '.', '1', '2'},
},
want: false,
},
{
name: "version matches minimum",
uname: syscall.Utsname{
Release: [65]int8{'5', '.', '1', '7', '.', '1', '2'},
},
want: true,
},
{
name: "major version high",
uname: syscall.Utsname{
Release: [65]int8{'6', '.', '1', '7', '.', '1', '2'},
},
want: true,
},
{
name: "minor version high",
uname: syscall.Utsname{
Release: [65]int8{'5', '.', '1', '8', '.', '1', '2'},
},
want: true,
},
{
name: "patch version high",
uname: syscall.Utsname{
Release: [65]int8{'5', '.', '1', '7', '.', '1', '3'},
},
want: true,
},
}

for _, c := range cases {
Expand Down

0 comments on commit b9d58ad

Please sign in to comment.