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 e6ab172
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/sysctl/sysctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 +49,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 e6ab172

Please sign in to comment.