Skip to content

Commit

Permalink
Add space trimming check in sysctl.Validate
Browse files Browse the repository at this point in the history
Sync with containers/podman#11224

Signed-off-by: Yan-Ming Li <[email protected]>
  • Loading branch information
xatier committed Aug 17, 2021
1 parent 828ae8f commit 53f74fc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/sysctl/sysctl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sysctl

import (
"fmt"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -30,6 +31,12 @@ func Validate(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
Expand All @@ -43,7 +50,7 @@ func Validate(strSlice []string) (map[string]string, error) {
}
}
if !foundMatch {
return nil, errors.Errorf("sysctl '%s' is not whitelisted", arr[0])
return nil, errors.Errorf("sysctl '%s' is not allowed", arr[0])
}
}
return sysctl, nil
Expand Down

0 comments on commit 53f74fc

Please sign in to comment.