Skip to content

Commit 5f6ed84

Browse files
committed
libcontainer/configs/config: Clear hook environ variables on empty Env
The runtime spec has [1]: * env (array of strings, OPTIONAL) with the same semantics as IEEE Std 1003.1-2008's environ. And running execle or similar with NULL env results in an empty environent: $ cat test.c #include <unistd.h> int main() { return execle("/usr/bin/env", "env", NULL, NULL); } $ cc -o test test.c $ ./test ...no output... Go's Cmd.Env, on the other hand, has [2]: If Env is nil, the new process uses the current process's environment. This commit works around that by setting a single dummy environment variable in those cases to avoid leaking the runtime environment into the hooks. [1]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#posix-platform-hooks [2]: https://golang.org/pkg/os/exec/#Cmd Signed-off-by: W. Trevor King <[email protected]>
1 parent b50fa98 commit 5f6ed84

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

libcontainer/configs/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ func (c Command) Run(s HookState) error {
320320
Stdout: &stdout,
321321
Stderr: &stderr,
322322
}
323+
if cmd.Env == nil {
324+
cmd.Env = []string{"_GO_DOES_NOT_PROVIDE_A_WAY_TO_CLEAR_ENV="}
325+
}
323326
if err := cmd.Start(); err != nil {
324327
return err
325328
}

0 commit comments

Comments
 (0)