getsops / sops

Simple and flexible tool for managing secrets
https://getsops.io/
Mozilla Public License 2.0
17.06k stars 880 forks source link

Do not ignore errors when trying to parse a config file #1614

Closed felixfontein closed 1 month ago

felixfontein commented 2 months ago

Found while playing around with #1613: sops --config /does/not/exist encrypt foo.sops.yml resulted in a panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1127533]

goroutine 1 [running]:
github.com/getsops/sops/v3/cmd/sops/common.newYamlStore(0x0)
    /path/to/sops/cmd/sops/common/common.go:58 +0x13
github.com/getsops/sops/v3/cmd/sops/common.StoreForFormat(...)
    /path/to/sops/cmd/sops/common/common.go:164
github.com/getsops/sops/v3/cmd/sops/common.DefaultStoreForPathOrFormat(0x0, {0xc0001800a0, 0x46}, {0x0?, 0x14974f9?})
    /path/to/sops/cmd/sops/common/common.go:179 +0x9d
main.inputStore(0xc00018d4a0, {0xc0001800a0, 0x46})
    /path/to/sops/cmd/sops/main.go:2059 +0x65
main.main.func10(0xc00018d4a0)
    /path/to/sops/cmd/sops/main.go:902 +0x1cc
github.com/urfave/cli.HandleAction({0x1226900?, 0x1503850?}, 0x7?)
    /path/to/sops/vendor/github.com/urfave/cli/app.go:524 +0x50
github.com/urfave/cli.Command.Run({{0x14887a3, 0x7}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x14c7d82, 0x30}, {0x0, ...}, ...}, ...)
    /path/to/sops/vendor/github.com/urfave/cli/command.go:175 +0x67c
github.com/urfave/cli.(*App).Run(0xc0004e2540, {0xc000138000, 0x5, 0x5})
    /path/to/sops/vendor/github.com/urfave/cli/app.go:277 +0xb3b
main.main()
    /path/to/sops/cmd/sops/main.go:1839 +0x6be5
felixfontein commented 2 months ago

Note that sops --config /does/not/exist --encrypt foo.sops.yml (not using the subcommand) doesn't have this problem since it first checks whether the config path exists.

felixfontein commented 1 month ago

@onedr0p @sabre1041 thanks for reviewing this!