Skip to content

Commit

Permalink
Ensure only numeric part of systemd version is converted to int (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZauberNerd committed Jun 12, 2024
1 parent 3462167 commit 54a528a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/agent/hooks/kcrypt_uki.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hook
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 54a528a

Please sign in to comment.