From 487ea813163903df78e5449b9c9b1cc02cef6ae2 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Sat, 27 May 2023 16:04:59 +0000 Subject: [PATCH] Fix npe in exec resize when exec errored In cases where an exec start failed the exec process will be nil even though the channel to signal that the exec started was closed. Ideally ExecConfig would get a nice refactor to handle this case better (ie. it's not started so don't close that channel). This is a minimal fix to prevent NPE. Luckilly this would only get called by a client and only the http request goroutine gets the panic (http lib recovers the panic). Signed-off-by: Brian Goff --- daemon/resize.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/daemon/resize.go b/daemon/resize.go index d1325e629784c..8e350fbbc2e7d 100644 --- a/daemon/resize.go +++ b/daemon/resize.go @@ -5,6 +5,8 @@ import ( "errors" "strconv" "time" + + "github.com/docker/docker/errdefs" ) // ContainerResize changes the size of the TTY of the process running @@ -48,6 +50,10 @@ func (daemon *Daemon) ContainerExecResize(name string, height, width int) error select { case <-ec.Started: + // An error may have occurred, so ec.Process may be nil. + if ec.Process == nil { + return errdefs.InvalidParameter(errors.New("exec process is not started")) + } return ec.Process.Resize(context.Background(), uint32(width), uint32(height)) case <-timeout.C: return errors.New("timeout waiting for exec session ready")