Skip to content

fix(docker): nil-guard remaining convertFrom*/convertToMount helpers#658

Merged
CybotTM merged 1 commit into
mainfrom
fix/issue-654
May 14, 2026
Merged

fix(docker): nil-guard remaining convertFrom*/convertToMount helpers#658
CybotTM merged 1 commit into
mainfrom
fix/issue-654

Conversation

@CybotTM
Copy link
Copy Markdown
Member

@CybotTM CybotTM commented May 14, 2026

Summary

Closes #654. Sibling-hunt completion of the convert.go family of nil-guard gaps that #619 / #626 / #632 / #648 started.

PR #648 added nil-guards to the convertFrom* swarm/event helpers and ContainerServiceAdapter.Create. The follow-up audit found 4 more helpers in core/adapters/docker/ with the same defense-in-depth gap:

Helper Risk
convertFromAPIContainer(c *containertypes.Summary) derefs c.Names, c.ID, c.Image, c.Created, c.Labels, c.State
convertFromNetworkResource(n *networktypes.Summary) derefs n.Name, n.IPAM.Driver, n.Containers
convertFromNetworkInspect(n *networktypes.Inspect) derefs n.Name, n.IPAM, n.Containers
convertToMount(m *domain.Mount) derefs m.Type

All four are reached via &loopVar from a range over a slice in production, so no live panic exists today. The signature contract is unsafe though — and convertToMount was especially asymmetric: every other convertTo* helper in container.go (convertToHostConfig, convertToNetworkingConfig, convertToEndpointSettings, convertToContainerConfig) already nil-guarded its argument.

Changes

Why "sibling-hunt completion"

This closes the convert.go family that #619 (Exec.Create / Run), #626 (convertTo* swarm/mount), #632 / #648 (convertFrom* swarm/event + Container.Create) chipped away at. After this merges, every convertTo* and convertFrom* helper in core/adapters/docker/ nil-guards its pointer argument — the unsafe-signature class is closed.

Test plan

  • go test ./core/adapters/docker/ -count=1 -short -race — all pass (existing happy-path tests in convert_mutation_test.go / convert_test.go / container_convert_test.go continue to pass, confirming the new guards don't regress anything)
  • golangci-lint run ./... — 0 issues
  • New nil-input tests pass with failOnPanic (would catch a missing guard)
  • New happy-path tests pin the contract for the 4 newly-guarded helpers

Copilot AI review requested due to automatic review settings May 14, 2026 06:28
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests labels May 14, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements defense-in-depth nil guards for several conversion functions in the Docker adapter, specifically convertToMount, convertFromAPIContainer, convertFromNetworkResource, and convertFromNetworkInspect, to prevent potential nil-pointer dereferences. Comprehensive regression tests have been added to verify these guards and ensure no regressions on valid inputs. I have no feedback to provide as there were no review comments to evaluate.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes a defense-in-depth audit in the Docker adapter by adding missing nil-guards to remaining convertFrom* helpers in convert.go and the asymmetric convertToMount helper in container.go, preventing potential nil-pointer panics from unsafe direct calls (while keeping current production behavior unchanged).

Changes:

  • Add early-return nil-guards for convertFromAPIContainer, convertFromNetworkResource, convertFromNetworkInspect, and convertToMount.
  • Add regression tests covering nil-input behavior (panic-free) plus happy-path sanity checks.
  • Document the fix in CHANGELOG.md under “Fixed”.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
core/adapters/docker/convert.go Adds nil-guards (zero-value / nil returns) and rationale godoc for remaining convertFrom* helpers.
core/adapters/docker/container.go Adds a nil-guard and godoc rationale to convertToMount to match other convertTo* helpers.
core/adapters/docker/convert_nil_test.go Adds nil-input regression tests + happy-path sanity checks for the newly guarded helpers.
CHANGELOG.md Records the defense-in-depth fix and references the related issue/PR lineage.

@CybotTM CybotTM enabled auto-merge May 14, 2026 11:10
Sibling-hunt completion of the convert.go family of nil-guard gaps that
PR #648 started. Four helpers in core/adapters/docker/ retained
unguarded pointer derefs after #648:

- convertFromAPIContainer(c *containertypes.Summary) -> derefs c.Names,
  c.ID, c.Image, c.Created, c.Labels, c.State
- convertFromNetworkResource(n *networktypes.Summary) -> derefs n.Name,
  n.IPAM.Driver, n.Containers
- convertFromNetworkInspect(n *networktypes.Inspect) -> derefs n.Name,
  n.IPAM, n.Containers
- convertToMount(m *domain.Mount) -> derefs m.Type

All four are reached via &loopVar from a range over a slice in
production, so no live panic exists today. The signature contract is
unsafe though, and convertToMount was especially asymmetric: every
other convertTo* helper in container.go (convertToHostConfig,
convertToNetworkingConfig, convertToEndpointSettings,
convertToContainerConfig) already nil-guarded its argument.

Each helper now early-returns the appropriate zero value (nil for the
pointer-returning convertFromNetworkInspect, mirroring
convertFromSwarmService from #648; zero struct value for the others)
and gains a godoc note explaining the defense-in-depth rationale.

Adds nil-input + happy-path regression tests in convert_nil_test.go
using the existing failOnPanic helper.

Same bug class as #619 / #626 / #632 / #648.

Closes #654

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@github-actions
Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval for maintainer PR

All automated quality gates passed. See SECURITY_CONTROLS.md for compensating controls.

@github-actions
Copy link
Copy Markdown

✅ Mutation Testing Results

Mutation Score: 100.00% (threshold: 60%)

✨ Good job! Mutation score meets the threshold.

What is mutation testing?

Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.

  • Killed mutants: Tests caught the mutation (good!)
  • Survived mutants: Tests missed the mutation (needs improvement)

@CybotTM CybotTM added this pull request to the merge queue May 14, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.85%. Comparing base (b6b6009) to head (aec3429).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #658      +/-   ##
==========================================
- Coverage   87.88%   87.85%   -0.03%     
==========================================
  Files          88       88              
  Lines       10978    11068      +90     
==========================================
+ Hits         9648     9724      +76     
- Misses       1086     1096      +10     
- Partials      244      248       +4     
Flag Coverage Δ
integration 87.83% <100.00%> (-0.05%) ⬇️
unittests 84.98% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Merged via the queue into main with commit d8415a9 May 14, 2026
27 checks passed
@CybotTM CybotTM deleted the fix/issue-654 branch May 14, 2026 11:21
techsolo12 pushed a commit to techsolo12/ofelia that referenced this pull request May 14, 2026
## Summary

Cut the existing `[Unreleased]` CHANGELOG block at
[fad5239](netresearch@fad5239)
into a versioned `[0.25.0] - 2026-05-14` heading, and fill in two
entries for PRs that landed after the previous `[Unreleased]` writeups:

- **### Security** — Go toolchain `1.26.2` → `1.26.3`
([netresearch#662](netresearch#662)). Clears six
stdlib advisories reachable from this codebase (`net/mail`,
`html/template`, `net`, `net/http`); refreshes direct deps
(`docker/cli`, `golang.org/x/{crypto,term,text}`) and the full indirect
graph. Post-bump `govulncheck` is down to the two unfixable upstream
moby advisories on `docker/docker` v28.5.2.
- **### Fixed** — `MaxRuntime` cancellation now stops *and removes* the
container/service
([netresearch#659](netresearch#659), fixes
[netresearch#655](netresearch#655)). Completes
[netresearch#651](netresearch#651 deadline wiring
with a fresh `context.WithTimeout(context.Background(),
jobCleanupTimeout)` cleanup context so stop/remove still runs after the
parent deadline fires. Mirrored into `RunServiceJob`.

## Headline changes since v0.24.0

- **Security**: Go 1.26.3 toolchain, three silent-downgrade vectors
closed (`https://` mTLS, SMTP STARTTLS default, webhook allow-list
typo), fail-closed on `tcp+tls://` without cert material
([netresearch#660](netresearch#660),
[netresearch#646](netresearch#646),
[netresearch#662](netresearch#662))
- **New**: `tcp+tls://` `DOCKER_HOST` scheme re-enabled
([netresearch#625](netresearch#625));
`DOCKER_TLS_VERIFY` / `DOCKER_CERT_PATH` honored
([netresearch#613](netresearch#613))
- **Correctness**: bounded contexts in scheduler / health / Docker pings
([netresearch#636](netresearch#636),
[netresearch#651](netresearch#651));
orphan-container cleanup on MaxRuntime
([netresearch#659](netresearch#659)); pervasive
nil-guard pass across the Docker adapter
([netresearch#626](netresearch#626),
[netresearch#639](netresearch#639),
[netresearch#648](netresearch#648),
[netresearch#658](netresearch#658))
- **Refactor / DX**: unified Docker host / scheme resolution
([netresearch#629](netresearch#629)); webhook global
config dual-store collapsed
([netresearch#637](netresearch#637)); `[global]`
label handling unified across all subsystems
([netresearch#661](netresearch#661))

## Version bump rationale

Pre-1.0 semver — minor bump because the range includes one `feat:`
([netresearch#625](netresearch#625) — `tcp+tls://`
scheme re-enabled), several `fix(security):` PRs that surface
previously-silent downgrades, and the `[global]` label-handling rework.
The webhook key rename in
[netresearch#620](netresearch#620) /
[netresearch#637](netresearch#637) is shipped under
`### Deprecated` (legacy `ofelia.webhooks` form keeps working with a
one-shot warning), not as a breaking change.

## Notes

- This PR touches **only `CHANGELOG.md`** — matches the v0.24.0 prep
pattern ([netresearch#602](netresearch#602)). The
Release workflow injects the version into `cli.Version` via ldflags from
the tag, so no `cli/version.go` edit is needed.
- After merge: signed annotated tag `v0.25.0` will be pushed to the
merge commit, triggering
[`release-go-app.yml`](https://github.com/netresearch/.github/blob/main/.github/workflows/release-go-app.yml)
for binaries, container image, cosign `--bundle` signatures, and SLSA
attestations.
- Contributor thanks will be added directly to the GitHub release
description (not the CHANGELOG, per project convention from v0.24.0).

## Test plan

- [x] `go build ./...` clean
- [ ] CI green on this PR
- [ ] CHANGELOG renders correctly on GitHub Files Changed tab
- [ ] After merge: signed annotated tag `v0.25.0` created on the merge
commit (`git tag -s v0.25.0 -m "v0.25.0"`) and pushed
- [ ] Release workflow run succeeds end-to-end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants