From a432eb4b3a0d06675889153e2993ae8ba8dc9149 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 13 Mar 2021 21:41:32 +0100 Subject: [PATCH] ContainerExecStart(): don't wrap getExecConfig() errors, and prevent panic daemon.getExecConfig() already returns typed errors; by wrapping those errors we may loose the actual reason for failures. Changing the error-type was originally added in 2d43d93410c29cec87deb9cd940c3b2a8af5fbbb, but I think it was not intentional to ignore already-typed errors. It was later refactored in a793564b2591035aec5412fbcbcccf220c773a4c, which added helper functions to create these errors, but kept the same behavior. Also adds error-handling to prevent a panic in situations where (although unlikely) `daemon.containers.Get()` would not return a container. Signed-off-by: Sebastiaan van Stijn --- daemon/exec.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/daemon/exec.go b/daemon/exec.go index 302842196b..b466d610fe 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -158,7 +158,7 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin ec, err := daemon.getExecConfig(name) if err != nil { - return errExecNotFound(name) + return err } ec.Lock() @@ -176,6 +176,9 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin ec.Unlock() c := daemon.containers.Get(ec.ContainerID) + if c == nil { + return containerNotFound(ec.ContainerID) + } logrus.Debugf("starting exec command %s in container %s", ec.ID, c.ID) attributes := map[string]string{ "execID": ec.ID,