Skip to content

Commit 2fff3d6

Browse files
committed
libct: check cmd.Err after exec.Command call
Theoretically, exec.Command can set cmd.Err. Practically, this should never happen (Linux, Go <= 1.26, exePath is absolute), but in the unlikely case it does, let's fail early. This is related to the recently introduced cloneCmd which chooses to not copy the Err field. Theoretically, exec.Command can set Err and so the first call to cmd.Start will fail (since Err != nil), and the second call to cmd.Start may succeed because Err == nil. Yet, this scenario is highly unlikely, but better be safe than sorry. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 73d7d7d commit 2fff3d6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

libcontainer/container_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ func (c *Container) newParentProcess(p *Process) (parentProcess, error) {
528528
}
529529

530530
cmd := exec.Command(exePath, "init")
531+
// Theoretically, exec.Command can set cmd.Err. Practically, this
532+
// should never happen (Linux, Go <= 1.26, exePath is absolute),
533+
// but in the unlikely case it just did, let's fail early.
534+
if cmd.Err != nil {
535+
return nil, fmt.Errorf("exec.Command: %w", cmd.Err)
536+
}
531537
cmd.Args[0] = os.Args[0]
532538
cmd.Stdin = p.Stdin
533539
cmd.Stdout = p.Stdout

0 commit comments

Comments
 (0)