From ba4ecfe7dc5e5bb1a59582071cc7fdbd12f4bddb Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Mon, 23 Nov 2020 15:51:11 +0200 Subject: [PATCH] kernel: more agressively sanitize full kernel version Trim illegal characters from the beginning and end of the kernel version string. Label values must start and end with an alphanumeric and we want to have some 'version.full' label, even if a sanitized one. --- source/kernel/kernel.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/kernel/kernel.go b/source/kernel/kernel.go index c1334256f..c6d4fce02 100644 --- a/source/kernel/kernel.go +++ b/source/kernel/kernel.go @@ -19,6 +19,7 @@ package kernel import ( "log" "regexp" + "strings" "sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source/internal/kernelutils" @@ -114,6 +115,8 @@ func parseVersion() (map[string]string, error) { // Replace forbidden symbols fullRegex := regexp.MustCompile("[^-A-Za-z0-9_.]") full = fullRegex.ReplaceAllString(full, "_") + // Label values must start and end with an alphanumeric + full = strings.Trim(full, "-_.") version["full"] = full