mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
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 <ndevos@redhat.com>
This commit is contained in:
parent
1b0b26a7a6
commit
ebe378c79a
@ -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
|
||||
|
@ -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)")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user