From ebe378c79a11a8adcbf449200428e23769b4d267 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 17 Jun 2020 20:34:12 +0200 Subject: [PATCH] util: trim "\x00" characters from the kernel version It seems that convering the release component from the unix.Utsrelease type leaves some trailing "\x00" characters. While splitting the string to compare kernel versions, these additional characters might prevent converting the string to an int. Strip the additional characters before returning the string. Note: "\x00" characters are not visible when printing to a file or screen. They can be seen in hex-editors, or sending the output through 'xxd'. Fixes: #1167 Signed-off-by: Niels de Vos --- internal/util/util.go | 2 +- internal/util/util_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/util/util.go b/internal/util/util.go index bb4163486..b8e1b387a 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -148,7 +148,7 @@ func KernelVersion() (string, error) { if err != nil { return "", err } - return string(utsname.Release[:]), nil + return strings.TrimRight(string(utsname.Release[:]), "\x00"), nil } // GenerateVolID generates a volume ID based on passed in parameters and version, to be returned diff --git a/internal/util/util_test.go b/internal/util/util_test.go index a8451883c..52a113218 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -16,6 +16,7 @@ limitations under the License. package util import ( + "strings" "testing" ) @@ -151,4 +152,7 @@ func TestKernelVersion(t *testing.T) { if version == "" { t.Error("version is empty, this is unexpected?!") } + if strings.HasSuffix(version, "\x00") { + t.Error("version ends with \\x00 byte(s)") + } }