Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pkg/kernelrelease): fixed kernelrelease regex for weird COS kernels. #355

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-]+)*)?$`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added an extra ? here

(?P\d+|\d*[a-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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that kernelrelease.String() method works fine too!

})
}
}
Expand Down
Loading