[GH-ISSUE #42] Calling HostsPerLine() before Add() results in a panic with plain vanilla macOS hosts file #15

Closed
opened 2026-03-02 05:08:07 +03:00 by kerem · 0 comments
Owner

Originally created by @rfay on GitHub (Apr 6, 2023).
Original GitHub issue: https://github.com/goodhosts/hostsfile/issues/42

If you call HostsPerLine() before Add(), (with a plain-vanilla macOS starter hosts file) you get a panic, like this:

panic: runtime error: index out of range [6] with length 4

goroutine 1 [running]:
github.com/goodhosts/hostsfile.(*Hosts).Add(0x140003264d0, {0x16eff7b14, 0x9}, {0x14000460fe0?, 0x1, 0x1})
	/Users/rfay/workspace/ddev/vendor/github.com/goodhosts/hostsfile/hosts.go:167 +0x3ec
github.com/ddev/ddev/pkg/ddevapp.AddHostEntry({0x16eff7b06, 0xd}, {0x16eff7b14, 0x9})
	/Users/rfay/workspace/ddev/pkg/ddevapp/hostname_mgt.go:140 +0xd4
github.com/ddev/ddev/cmd/ddev/cmd.glob..func30(0x1019e66c0?, {0x14000066600?, 0x2, 0x2})
	/Users/rfay/workspace/ddev/cmd/ddev/cmd/hostname.go:74 +0x20c
github.com/spf13/cobra.(*Command).execute(0x1019e66c0, {0x140000665a0, 0x2, 0x2})
	/Users/rfay/workspace/ddev/vendor/github.com/spf13/cobra/command.go:860 +0x4ac
github.com/spf13/cobra.(*Command).ExecuteC(0x1019e98c0)
	/Users/rfay/workspace/ddev/vendor/github.com/spf13/cobra/command.go:974 +0x354
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/rfay/workspace/ddev/vendor/github.com/spf13/cobra/command.go:902
github.com/ddev/ddev/cmd/ddev/cmd.Execute()
	/Users/rfay/workspace/ddev/cmd/ddev/cmd/root.go:143 +0x40
main.main()
	/Users/rfay/workspace/ddev/cmd/ddev/main.go:20 +0xac

This is demonstrated in a test repo: https://github.com/rfay/goodhostsbug/tree/broken

It's fixed by changing HostsPerLine() to later, see https://github.com/rfay/goodhostsbug

Originally created by @rfay on GitHub (Apr 6, 2023). Original GitHub issue: https://github.com/goodhosts/hostsfile/issues/42 If you call HostsPerLine() before Add(), (with a plain-vanilla macOS starter hosts file) you get a panic, like this: ``` panic: runtime error: index out of range [6] with length 4 goroutine 1 [running]: github.com/goodhosts/hostsfile.(*Hosts).Add(0x140003264d0, {0x16eff7b14, 0x9}, {0x14000460fe0?, 0x1, 0x1}) /Users/rfay/workspace/ddev/vendor/github.com/goodhosts/hostsfile/hosts.go:167 +0x3ec github.com/ddev/ddev/pkg/ddevapp.AddHostEntry({0x16eff7b06, 0xd}, {0x16eff7b14, 0x9}) /Users/rfay/workspace/ddev/pkg/ddevapp/hostname_mgt.go:140 +0xd4 github.com/ddev/ddev/cmd/ddev/cmd.glob..func30(0x1019e66c0?, {0x14000066600?, 0x2, 0x2}) /Users/rfay/workspace/ddev/cmd/ddev/cmd/hostname.go:74 +0x20c github.com/spf13/cobra.(*Command).execute(0x1019e66c0, {0x140000665a0, 0x2, 0x2}) /Users/rfay/workspace/ddev/vendor/github.com/spf13/cobra/command.go:860 +0x4ac github.com/spf13/cobra.(*Command).ExecuteC(0x1019e98c0) /Users/rfay/workspace/ddev/vendor/github.com/spf13/cobra/command.go:974 +0x354 github.com/spf13/cobra.(*Command).Execute(...) /Users/rfay/workspace/ddev/vendor/github.com/spf13/cobra/command.go:902 github.com/ddev/ddev/cmd/ddev/cmd.Execute() /Users/rfay/workspace/ddev/cmd/ddev/cmd/root.go:143 +0x40 main.main() /Users/rfay/workspace/ddev/cmd/ddev/main.go:20 +0xac ``` This is demonstrated in a test repo: https://github.com/rfay/goodhostsbug/tree/broken It's fixed by changing HostsPerLine() to later, see https://github.com/rfay/goodhostsbug
kerem closed this issue 2026-03-02 05:08:07 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hostsfile#15
No description provided.