Skip to content

Commit 3e342bf

Browse files
Merge pull request cri-o#6450 from haircommander/homedir-drop
server: fail if HOME variable has a newline
2 parents 095f77c + 41dca27 commit 3e342bf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

server/container_create.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ func setupContainerUser(ctx context.Context, specgen *generate.Generator, rootfs
201201
for _, env := range specgen.Config.Process.Env {
202202
if strings.HasPrefix(env, "HOME=") {
203203
homedir = strings.TrimPrefix(env, "HOME=")
204+
if idx := strings.Index(homedir, `\n`); idx > -1 {
205+
return fmt.Errorf("invalid HOME environment; newline not allowed")
206+
}
204207
break
205208
}
206209
}

test/ctr.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,3 +1024,11 @@ function check_oci_annotation() {
10241024
! ps -p "$process" o pid=,stat= | grep -v 'Z'
10251025
done
10261026
}
1027+
1028+
@test "ctr HOME env newline invalid" {
1029+
start_crio
1030+
jq ' .envs = [{"key": "HOME=", "value": "/root:/sbin/nologin\\ntest::0:0::/:/bin/bash"}]' \
1031+
"$TESTDATA"/container_config.json > "$newconfig"
1032+
1033+
! crictl run "$newconfig" "$TESTDATA"/sandbox_config.json
1034+
}

0 commit comments

Comments
 (0)