Skip to content

Commit d5bb338

Browse files
Nepomuk5665ndeloof
authored andcommitted
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 <105591323+Nepomuk5665@users.noreply.github.com>
1 parent d91fc63 commit d5bb338

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

pkg/compose/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (c *monitor) Start(ctx context.Context) error {
147147
return err
148148
}
149149

150-
if inspect.State != nil && inspect.State.Restarting || inspect.State.Running {
150+
if inspect.State != nil && (inspect.State.Restarting || inspect.State.Running) {
151151
// State.Restarting is set by engine when container is configured to restart on exit
152152
// on ContainerRestart it doesn't (see https://github.com/moby/moby/issues/45538)
153153
// container state still is reported as "running"

0 commit comments

Comments
 (0)