mirror of
https://github.com/docker/compose.git
synced 2026-10-12 02:13:08 +00:00
Fix potential nil pointer dereference in container event monitoring
The condition for checking container restart state had incorrect operator precedence. The expression: inspect.State != nil && inspect.State.Restarting || inspect.State.Running is evaluated as: (inspect.State != nil && inspect.State.Restarting) || inspect.State.Running This means if inspect.State is nil and inspect.State.Restarting is false (which would trigger a panic), the code would attempt to access inspect.State.Running, causing a nil pointer dereference. This fix adds parentheses to ensure the nil check applies to both state checks: inspect.State != nil && (inspect.State.Restarting || inspect.State.Running) Signed-off-by: Nepomuk Crhonek <[email protected]>
This commit is contained in:
committed by
Nicolas De loof
parent
d91fc63813
commit
d5bb3387ca
@@ -147,7 +147,7 @@ func (c *monitor) Start(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if inspect.State != nil && inspect.State.Restarting || inspect.State.Running {
|
||||
if inspect.State != nil && (inspect.State.Restarting || inspect.State.Running) {
|
||||
// State.Restarting is set by engine when container is configured to restart on exit
|
||||
// on ContainerRestart it doesn't (see https://github.com/moby/moby/issues/45538)
|
||||
// container state still is reported as "running"
|
||||
|
||||
Reference in New Issue
Block a user