Ensure only numeric part of systemd version is converted to int (#362)

This commit is contained in:
Björn Brauer 2024-06-12 10:08:19 +02:00 committed by GitHub
parent 3462167492
commit 54a528a44a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {