mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
c.RWLayer: check for nil before use
Since commite9b9e4ace2has landed, there is a chance that container.RWLayer is nil (due to some half-removed container). Let's check the pointer before use to avoid any potential nil pointer dereferences, resulting in a daemon crash. Note that even without the abovementioned commit, it's better to perform an extra check (even it's totally redundant) rather than to have a possibility of a daemon crash. In other words, better be safe than sorry. [v2: add a test case for daemon.getInspectData] [v3: add a check for container.Dead and a special error for the case] Fixes:e9b9e4ace2Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
33
daemon/inspect_test.go
Normal file
33
daemon/inspect_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package daemon // import "github.com/docker/docker/daemon"
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/daemon/exec"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetInspectData(t *testing.T) {
|
||||
c := &container.Container{
|
||||
ID: "inspect-me",
|
||||
HostConfig: &containertypes.HostConfig{},
|
||||
State: container.NewState(),
|
||||
ExecCommands: exec.NewStore(),
|
||||
}
|
||||
|
||||
d := &Daemon{
|
||||
linkIndex: newLinkIndex(),
|
||||
configStore: &config.Config{},
|
||||
}
|
||||
|
||||
_, err := d.getInspectData(c)
|
||||
assert.Error(t, err)
|
||||
|
||||
c.Dead = true
|
||||
_, err = d.getInspectData(c)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
Reference in New Issue
Block a user