twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.35k stars 493 forks source link

Segfault `.chezmoiexternal.toml` Has Headers Without Bodies #3693

Closed Logicer16 closed 7 months ago

Logicer16 commented 7 months ago

Describe the bug

When a .chezmoiexternal.toml contains a header without content, chezmoi experiences a segfault.

To reproduce

.chezmoiexternal.toml:

[".config"]

Expected behavior

Graceful handling of the error.

Output of command with the --verbose flag

$ chezmoi --verbose apply
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x188 pc=0x1025af54c]

goroutine 1 [running]:
github.com/twpayne/chezmoi/v2/internal/chezmoi.(*SourceState).addExternal(0x14000362c00, {0x140007b0f40, 0x40}, {0x140007b0f40, 0x2b})
    github.com/twpayne/chezmoi/v2/internal/chezmoi/sourcestate.go:1333 +0x58c
github.com/twpayne/chezmoi/v2/internal/chezmoi.(*SourceState).Read.func2({0x140007b0f40, 0x40}, {0x103494688, 0x140003d6f70}, {0x0?, 0x0?})
    github.com/twpayne/chezmoi/v2/internal/chezmoi/sourcestate.go:975 +0x1260
github.com/twpayne/chezmoi/v2/internal/chezmoi.walkSourceDir({0x103499900, 0x140003b9680}, {0x140007b0f40, 0x40}, {0x103494688, 0x140003d6f70}, 0x140006b3158)
    github.com/twpayne/chezmoi/v2/internal/chezmoi/system.go:202 +0x5c
github.com/twpayne/chezmoi/v2/internal/chezmoi.walkSourceDir({0x103499900, 0x140003b9680}, {0x14000402960, 0x2a}, {0x103494688, 0x140003d69c0}, 0x140006b3158)
    github.com/twpayne/chezmoi/v2/internal/chezmoi/system.go:229 +0x268
github.com/twpayne/chezmoi/v2/internal/chezmoi.WalkSourceDir({0x103499900, 0x140003b9680}, {0x14000402960, 0x2a}, 0x140006b3158)
    github.com/twpayne/chezmoi/v2/internal/chezmoi/system.go:181 +0x8c
github.com/twpayne/chezmoi/v2/internal/chezmoi.(*SourceState).Read(0x14000362c00, {0x1034909e0, 0x103e3bd00}, 0x1400061b8c0)
    github.com/twpayne/chezmoi/v2/internal/chezmoi/sourcestate.go:1046 +0x190
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).newSourceState(0x140002e5008, {0x1034909e0, 0x103e3bd00}, 0x1400022d508, {0x0, 0x0, 0x1?})
    github.com/twpayne/chezmoi/v2/internal/cmd/config.go:1752 +0x834
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).getSourceState(0x140002e5008, {0x1034909e0?, 0x103e3bd00?}, 0x1031ed120?)
    github.com/twpayne/chezmoi/v2/internal/cmd/config.go:1417 +0x5c
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).applyArgs(0x140002e5008, {0x1034909e0, 0x103e3bd00}, {0x103499900, 0x140003b9700}, {0x1400004204d, 0x10}, {0x14000392ff0, 0x0, 0x1}, ...)
    github.com/twpayne/chezmoi/v2/internal/cmd/config.go:621 +0x38c
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).runApplyCmd(0x140002e5008, 0xfd7a866000000000?, {0x14000392ff0, 0x0, 0x1})
    github.com/twpayne/chezmoi/v2/internal/cmd/applycmd.go:39 +0xec
github.com/spf13/cobra.(*Command).execute(0x1400022d508, {0x14000392fd0, 0x1, 0x1})
    github.com/spf13/cobra@v1.8.0/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x140005df208)
    github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
    github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).execute(0x140006b3dd8?, {0x1400011a310, 0x2, 0x2})
    github.com/twpayne/chezmoi/v2/internal/cmd/config.go:1223 +0x70
github.com/twpayne/chezmoi/v2/internal/cmd.runMain({{0x1031466fc, 0x6}, {0x103147860, 0x28}, {0x103147590, 0x14}, {0x1031474b0, 0x8}}, {0x1400011a310, 0x2, ...})
    github.com/twpayne/chezmoi/v2/internal/cmd/cmd.go:270 +0x18c
github.com/twpayne/chezmoi/v2/internal/cmd.Main({{0x1031466fc, 0x6}, {0x103147860, 0x28}, {0x103147590, 0x14}, {0x1031474b0, 0x8}}, {0x1400011a310?, 0x102077db8?, ...})
    github.com/twpayne/chezmoi/v2/internal/cmd/cmd.go:106 +0x54
main.main()
    github.com/twpayne/chezmoi/v2/main.go:24 +0xd8

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.47.3, commit 4f76edb5295068569d7c6311020ac0094c77ef44, built at 2024-03-31T18:12:53Z, built by Homebrew ok latest-version v2.47.3 ok os-arch darwin/arm64 ok uname Darwin .local 23.5.0 Darwin Kernel Version 23.5.0: Tue Mar 26 20:54:53 PDT 2024; root:xnu-10063.120.88.501.3~2/RELEASE_ARM64_T8122 arm64 ok go-version go1.22.1 (gc) ok executable /opt/homebrew/bin/chezmoi ok upgrade-method brew-upgrade ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2024-03-18T17:43:17+11:00 ok source-dir ~/.local/share/chezmoi/HOME is a directory ok suspicious-entries no suspicious entries warning working-tree ~/.local/share/chezmoi is a git working tree (dirty) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/zsh ok cd-args /bin/zsh info diff-command not set ok edit-command found /usr/bin/env ok edit-args /usr/bin/env code --wait --new-window ok git-command found /opt/homebrew/bin/git, version 2.44.0 ok merge-command found /usr/bin/vimdiff ok shell-command found /bin/zsh ok shell-args /bin/zsh info age-command age not found in $PATH ok gpg-command found /opt/homebrew/bin/gpg, version 2.4.5 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info bitwarden-secrets-command bws not found in $PATH info dashlane-command dcli not found in $PATH info doppler-command doppler not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info vlt-command vlt not found in $PATH info secret-command not set ```
twpayne commented 7 months ago

Thanks for reporting this! Should be fixed by #3694.