Fix the issue that pod or container config file without metadata will crash containerd

Because RunPodSandbox and CreateContainer will access metadata
without check, pod or container config file without metadata will
crash containerd.

This patch add checks to handle the issue.

Fixes: #1009

Signed-off-by: Hui Zhu <teawater@hyper.sh>
This commit is contained in:
Hui Zhu 2018-12-25 13:21:43 +08:00
parent e5bd9b62d8
commit 3bfef01589
2 changed files with 10 additions and 2 deletions

View File

@ -92,7 +92,11 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
// Reserve the container name to avoid concurrent `CreateContainer` request creating // Reserve the container name to avoid concurrent `CreateContainer` request creating
// the same container. // the same container.
id := util.GenerateID() id := util.GenerateID()
name := makeContainerName(config.GetMetadata(), sandboxConfig.GetMetadata()) metadata := config.GetMetadata()
if metadata == nil {
return nil, errors.New("container config must include metadata")
}
name := makeContainerName(metadata, sandboxConfig.GetMetadata())
logrus.Debugf("Generated id %q for container %q", id, name) logrus.Debugf("Generated id %q for container %q", id, name)
if err = c.containerNameIndex.Reserve(name, id); err != nil { if err = c.containerNameIndex.Reserve(name, id); err != nil {
return nil, errors.Wrapf(err, "failed to reserve container name %q", name) return nil, errors.Wrapf(err, "failed to reserve container name %q", name)

View File

@ -58,7 +58,11 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
// Generate unique id and name for the sandbox and reserve the name. // Generate unique id and name for the sandbox and reserve the name.
id := util.GenerateID() id := util.GenerateID()
name := makeSandboxName(config.GetMetadata()) metadata := config.GetMetadata()
if metadata == nil {
return nil, errors.New("sandbox config must include metadata")
}
name := makeSandboxName(metadata)
logrus.Debugf("Generated id %q for sandbox %q", id, name) logrus.Debugf("Generated id %q for sandbox %q", id, name)
// Reserve the sandbox name to avoid concurrent `RunPodSandbox` request starting the // Reserve the sandbox name to avoid concurrent `RunPodSandbox` request starting the
// same sandbox. // same sandbox.