summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2021-08-17 13:38:19 +0000
committerGitHub <noreply@github.com>2021-08-17 13:38:19 +0000
commitedf9ec38e40bd2471c870c9bbf3b2685d5e45fa7 (patch)
treee70e2d7816eaac63f5502b99b7e7768be926cddb
parentde4d7b2f7c5cc8199fefee904f0b4976de812ae9 (diff)
parentd9975643428c63f5402c0ac253e8c324a14ba15e (diff)
downloadpodman-edf9ec38e40bd2471c870c9bbf3b2685d5e45fa7.tar.gz
podman-edf9ec38e40bd2471c870c9bbf3b2685d5e45fa7.tar.bz2
podman-edf9ec38e40bd2471c870c9bbf3b2685d5e45fa7.zip
Merge pull request #11224 from xatier/master
Add space trimming check in ValidateSysctls
-rw-r--r--pkg/util/utils.go6
-rw-r--r--pkg/util/utils_test.go23
2 files changed, 29 insertions, 0 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go
index 774590f44..63fad0286 100644
--- a/pkg/util/utils.go
+++ b/pkg/util/utils.go
@@ -618,6 +618,12 @@ func ValidateSysctls(strSlice []string) (map[string]string, error) {
if len(arr) < 2 {
return nil, errors.Errorf("%s is invalid, sysctl values must be in the form of KEY=VALUE", val)
}
+
+ trimmed := fmt.Sprintf("%s=%s", strings.TrimSpace(arr[0]), strings.TrimSpace(arr[1]))
+ if trimmed != val {
+ return nil, errors.Errorf("'%s' is invalid, extra spaces found", val)
+ }
+
if validSysctlMap[arr[0]] {
sysctl[arr[0]] = arr[1]
continue
diff --git a/pkg/util/utils_test.go b/pkg/util/utils_test.go
index 027acbdab..62de7509f 100644
--- a/pkg/util/utils_test.go
+++ b/pkg/util/utils_test.go
@@ -1,6 +1,7 @@
package util
import (
+ "fmt"
"testing"
"time"
@@ -259,6 +260,28 @@ func TestValidateSysctlBadSysctl(t *testing.T) {
assert.Error(t, err)
}
+func TestValidateSysctlBadSysctlWithExtraSpaces(t *testing.T) {
+ expectedError := "'%s' is invalid, extra spaces found"
+
+ // should fail fast on first sysctl
+ strSlice1 := []string{
+ "net.ipv4.ping_group_range = 0 0",
+ "net.ipv4.ping_group_range=0 0 ",
+ }
+ _, err := ValidateSysctls(strSlice1)
+ assert.Error(t, err)
+ assert.Equal(t, err.Error(), fmt.Sprintf(expectedError, strSlice1[0]))
+
+ // should fail on second sysctl
+ strSlice2 := []string{
+ "net.ipv4.ping_group_range=0 0",
+ "net.ipv4.ping_group_range=0 0 ",
+ }
+ _, err = ValidateSysctls(strSlice2)
+ assert.Error(t, err)
+ assert.Equal(t, err.Error(), fmt.Sprintf(expectedError, strSlice2[1]))
+}
+
func TestCoresToPeriodAndQuota(t *testing.T) {
cores := 1.0
expectedPeriod := DefaultCPUPeriod