guumaster / hostctl

Your dev tool to manage /etc/hosts like a pro!

Home Page:http://guumaster.github.io/hostctl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SegFault - profile.RemoveHostNames -

mattkasun opened this issue · comments

crash.go.txt
Describe the bug
profile.RemoveHostNames() does not update profile.IPList and will result in a segfault during a file.Flush()

To Reproduce
run crash.go

Expected behavior
host file is updated

Screenshots

mkasun@endeavour /t/crash> sudo go run crash.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x50d09f]

goroutine 1 [running]:
github.com/guumaster/hostctl/pkg/types.(*Profile).Render(0xc0002b71c0, {0x7f4cb4548c80, 0xc0000ae470})
	/root/go/pkg/mod/github.com/guumaster/hostctl@v1.1.1/pkg/types/profile.go:118 +0x25f
github.com/guumaster/hostctl/pkg/file.(*File).writeToFile(0xc0002b6e40, {0x671880, 0xc0000ae470})
	/root/go/pkg/mod/github.com/guumaster/hostctl@v1.1.1/pkg/file/file.go:210 +0x307
github.com/guumaster/hostctl/pkg/file.(*File).Flush(0xc0002b6e40)
	/root/go/pkg/mod/github.com/guumaster/hostctl@v1.1.1/pkg/file/file.go:179 +0xd7
main.DeleteDNSEntry({0x6210f7, 0x6}, {0x621589, 0x7}, 0x89)
	/tmp/crash/crash.go:65 +0x14e
main.main()
	/tmp/crash/crash.go:21 +0x146
exit status 2

System (please complete the following information):

mkasun@endeavour /t/crash [1]> uname -a
Linux endeavour 5.16.14-arch1-1 #1 SMP PREEMPT Fri, 11 Mar 2022 17:40:36 +0000 x86_64 GNU/Linux

Additional context
PR #80

I'll close this after releasing a new version. Thanks @mattkasun