Skip to content

docker: nil-guard remaining convertFrom*/convertToMount helpers in convert.go (sibling of #632) #654

@CybotTM

Description

@CybotTM

Sibling-hunt finding from PR #648 review.

PR #648 added nil-guards to convertFromSwarmService, convertTaskTemplateFromSwarm,
convertFromSwarmTask, convertFromSDKEvent, and Container.Create.
4 more helpers in core/adapters/docker/ retain unguarded pointer
derefs:

File:Line Helper Risk
convert.go:127 convertFromAPIContainer(c *containertypes.Summary) derefs c.Names, c.ID, c.Image
convert.go:148 convertFromNetworkResource(n *networktypes.Summary) derefs n.Name, n.IPAM.Driver, n.Containers
convert.go:197 convertFromNetworkInspect(n *networktypes.Inspect) derefs n.Name, n.IPAM, n.Containers
container.go:453 convertToMount(m *domain.Mount) mount.Mount derefs m.Type

All four are reached via &loopVar from a range over a slice, so
no live panic exists today. The signature contract is unsafe,
though — same defense-in-depth concern PR #648 addressed for the
swarm/event family.

convertToMount is especially asymmetric: every other convertTo*
helper in container.go (convertToHostConfig, convertToNetworkingConfig,
convertToEndpointSettings, convertToContainerConfig) DOES guard
nil. Only convertToMount does not.

Suggested fix

Mirror PR #648's pattern: if x == nil { return zeroValue }
early-return + godoc + nil-input regression test using failOnPanic.

Severity

Low — defense-in-depth. Same bug class as #619 / #626 / #632.

Related

  • #622 — original
    audit
  • #626: convertTo*
    swarm/mount halves
  • #632: convertFrom*
    swarm/event halves
  • PR #648: fixed
    the symmetric From* + Container.Create half

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions