regclient / regclient

Docker and OCI Registry Client in Go and tooling using those libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Issue] `regctl` segfaults when configuration file is a directory

PigeonF opened this issue · comments

Current Behavior

regctl segfaults when ~/.regctl/config.json or REGCTL_CONFIG is a directory. This is obviously a user error (I stumbled across this because of a docker mount creating ~/.regctl/config.json as a directory), but regctl should probably give a proper error message instead of segfaulting (while regctl prints a warning, it seems there is still some error with dereferencing a null pointer).

Expected Behavior

regctl should print an error message instead of segfaulting.

Steps To Reproduce

$ cd $(mktemp -d)
$ mkdir foo
$ REGCTL_CONFIG=$(pwd)/foo regctl image copy docker.io/alpine ocidir://alpine
WARN[0000] Failed to load default config                 err="read /tmp/tmp.7HYeA15ho3/foo: is a directory"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x8777f6]

goroutine 1 [running]:
main.(*rootCmd).newRegClient(0xc00028c000)
        github.com/regclient/regclient/cmd/regctl/root.go:138 +0x596
main.(*imageCmd).runImageCopy(0xc0002d0000, 0xc0002d2608, {0xc0002a4640, 0x0?, 0x0?})
        github.com/regclient/regclient/cmd/regctl/image.go:784 +0x1af
github.com/spf13/cobra.(*Command).execute(0xc0002d2608, {0xc0002a4600, 0x2, 0x2})
        github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc00028e008)
        github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        github.com/spf13/cobra@v1.8.0/command.go:1032
main.main()
        github.com/regclient/regclient/cmd/regctl/main.go:29 +0x14e

Version

VCSTag:     v0.5.7
VCSRef:     unknown
VCSCommit:  unknown
VCSState:   unknown
VCSDate:    unknown
Platform:   linux/amd64
GoVer:      go1.22.2
GoCompiler: gc

Environment

  • Running as binary or container: binary
  • Host platform: NixOS
  • Registry description: n/a

Thank you for the report @PigeonF. This should be resolved by #738. If you encounter any further issues, feel free to pass them along.