Skip to content

Commit

Permalink
Merge pull request #3017 from wzshiming/fix/setenv
Browse files Browse the repository at this point in the history
Returns clearer error message for Setenv
  • Loading branch information
kolyshkin authored Jun 14, 2021
2 parents c4359f8 + 322c8fd commit 8726c70
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,19 @@ func populateProcessEnvironment(env []string) error {
for _, pair := range env {
p := strings.SplitN(pair, "=", 2)
if len(p) < 2 {
return fmt.Errorf("invalid environment '%v'", pair)
return fmt.Errorf("invalid environment variable: %q", pair)
}
if err := os.Setenv(p[0], p[1]); err != nil {
name, val := p[0], p[1]
if name == "" {
return fmt.Errorf("environment variable name can't be empty: %q", pair)
}
if strings.IndexByte(name, 0) >= 0 {
return fmt.Errorf("environment variable name can't contain null(\\x00): %q", pair)
}
if strings.IndexByte(val, 0) >= 0 {
return fmt.Errorf("environment variable value can't contain null(\\x00): %q", pair)
}
if err := os.Setenv(name, val); err != nil {
return err
}
}
Expand Down

0 comments on commit 8726c70

Please sign in to comment.