Skip to content

Commit

Permalink
fix(pkg/kernelrelease): fixed kernelrelease regex for weird COS kernels.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed Sep 9, 2024
1 parent 126a99b commit 5c896b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/kernelrelease/kernelrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

var (
kernelVersionPattern = regexp.MustCompile(`(?P<fullversion>^(?P<version>0|[1-9]\d*)\.(?P<patchlevel>0|[1-9]\d*)[.+]?(?P<sublevel>0|[1-9]\d*)?)(?P<fullextraversion>[-.+](?P<extraversion>\d+|\d*[a-zA-Z-][0-9a-zA-Z-]*)([\.+~](\d+|\d*[a-zA-Z-][0-9a-zA-Z-_]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$`)
kernelVersionPattern = regexp.MustCompile(`(?P<fullversion>^(?P<version>0|[1-9]\d*)\.(?P<patchlevel>0|[1-9]\d*)[.+]?(?P<sublevel>0|[1-9]\d*)?)(?P<fullextraversion>[-.+](?P<extraversion>\d+|\d*[a-zA-Z-][0-9a-zA-Z-]*)?([\.+~](\d+|\d*[a-zA-Z-][0-9a-zA-Z-_]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$`)
)

const (
Expand Down
15 changes: 15 additions & 0 deletions pkg/kernelrelease/kernelrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,26 @@ func TestFromString(t *testing.T) {
FullExtraversion: "-19.0009.28",
},
},
// See https://github.com/falcosecurity/falco/issues/3278
"strange cos version": {
kernelVersionStr: "5.15.146+",
want: KernelRelease{
Fullversion: "5.15.146",
Version: semver.Version{
Major: 5,
Minor: 15,
Patch: 146,
},
Extraversion: "",
FullExtraversion: "+",
},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got := FromString(tt.kernelVersionStr)
assert.DeepEqual(t, tt.want, got)
assert.Equal(t, got.String(), tt.kernelVersionStr)
})
}
}
Expand Down

0 comments on commit 5c896b1

Please sign in to comment.