From 54a528a44ab913fc4283934f96038d0616d4ab8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Brauer?= Date: Wed, 12 Jun 2024 10:08:19 +0200 Subject: [PATCH] Ensure only numeric part of systemd version is converted to int (#362) --- internal/agent/hooks/kcrypt_uki.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/agent/hooks/kcrypt_uki.go b/internal/agent/hooks/kcrypt_uki.go index 6082eb61..6526409b 100644 --- a/internal/agent/hooks/kcrypt_uki.go +++ b/internal/agent/hooks/kcrypt_uki.go @@ -3,6 +3,7 @@ package hook import ( "fmt" "os" + "regexp" "strconv" "strings" "time" @@ -32,6 +33,12 @@ func (k KcryptUKI) Run(c config.Config, spec v1.Spec) error { c.Logger.Errorf("could not get systemd version: %s", err) return err } + // Extract the numeric portion of the version string using a regular expression + re := regexp.MustCompile(`\d+`) + matches := re.FindString(systemdVersion) + if matches == "" { + return fmt.Errorf("could not extract numeric part from systemd version: %s", systemdVersion) + } // Change systemdVersion to int value systemdVersionInt, err := strconv.Atoi(systemdVersion) if err != nil {