pkg build: fix nil pointer dereference when releasing image only in registry by europaul · Pull Request #4212 · linuxkit/linuxkit · GitHub
Skip to content

pkg build: fix nil pointer dereference when releasing image only in registry#4212

Merged
justincormack merged 1 commit into
linuxkit:masterfrom
europaul:fix/nil-deref-release-tag
Mar 27, 2026
Merged

pkg build: fix nil pointer dereference when releasing image only in registry#4212
justincormack merged 1 commit into
linuxkit:masterfrom
europaul:fix/nil-deref-release-tag

Conversation

@europaul

Copy link
Copy Markdown
Contributor

- What I did

Fixed a nil pointer dereference (panic) in pkglib.Pkg.Build at build.go:588 that occurs when pushing with --release and the image already exists in the registry but not in the local cache.

This is a regression introduced in 4129cc7 (#4201), which removed the early return for missing local cache images to allow release tags to be pushed even when the digest tag already exists.

- How I did it

  • When desc is nil (image not in local cache) and a release is requested, pull the image into local cache before creating the release tag.
  • Guard the targetDocker block against nil descriptors — if nothing is in local cache, there is nothing to load into Docker.
  • Fixed the FindDescriptor mock in tests to return nil, nil when not found, matching the real implementation's documented behavior.
  • Added TestPushReleaseImageInRegistry regression test that reproduces the exact panic.

- How to verify it

Run the new test without the fix to see the panic:

cd src/cmd/linuxkit
git stash push -- pkglib/build.go
go test ./pkglib/ -run TestPushReleaseImageInRegistry -v
# panics with: nil pointer dereference at build.go:588
git stash pop

Run all tests with the fix:

make local
# All tests pass, including the new regression test

- Description for the changelog

Fix nil pointer dereference when pushing with --release and the image already exists in the registry but not in the local cache.

…egistry

When an image exists in the registry but not in local cache and a
release tag is requested, FindDescriptor returns nil causing a panic
at build.go:588. This was a regression introduced in 4129cc7 which
removed the early return for missing local cache images.

Fix by pulling the image into local cache when the descriptor is nil
and a release is needed. Also guard the targetDocker block against
nil descriptors, and fix the FindDescriptor mock to return nil,nil
(matching the real implementation) instead of an error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
@europaul europaul force-pushed the fix/nil-deref-release-tag branch from f92356f to 420d550 Compare March 25, 2026 17:54

@rucoder rucoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

test comment

Comment thread src/cmd/linuxkit/pkglib/build.go
@justincormack justincormack merged commit 3bf33c3 into linuxkit:master Mar 27, 2026
25 checks passed
europaul added a commit to europaul/eve that referenced this pull request Mar 27, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
@europaul europaul mentioned this pull request Mar 27, 2026
6 tasks
rene pushed a commit to lf-edge/eve that referenced this pull request Mar 27, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
europaul added a commit to europaul/eve that referenced this pull request Mar 31, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
(cherry picked from commit 691bb26)
europaul added a commit to europaul/eve that referenced this pull request Mar 31, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
(cherry picked from commit 691bb26)
rene pushed a commit to lf-edge/eve that referenced this pull request Apr 1, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
(cherry picked from commit 691bb26)
rene pushed a commit to lf-edge/eve that referenced this pull request Apr 2, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
(cherry picked from commit 691bb26)
europaul added a commit to europaul/eve that referenced this pull request Apr 7, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
(cherry picked from commit 691bb26)
rene pushed a commit to lf-edge/eve that referenced this pull request Apr 11, 2026
Update to include the fix from linuxkit/linuxkit#4212

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
(cherry picked from commit 691bb26)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants