UnnoTed / fileb0x

a better customizable tool to embed files in go; also update embedded files remotely without restarting the server
MIT License
634 stars 53 forks source link

Fix nil pointer dereference #16

Closed opalmer closed 6 years ago

opalmer commented 6 years ago

I was trying to use fileb0x on a project (running: fileb0x files.yml) but it was segfaulting:

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

goroutine 1 [running]:
github.com/UnnoTed/fileb0x/config.(*Config).Defaults(0x0, 0x0, 0x0)
    /home/opalmer/go/src/github.com/UnnoTed/fileb0x/config/config.go:35 +0x26
main.main()
    /home/opalmer/go/src/github.com/UnnoTed/fileb0x/main.go:65 +0x24d

I was able to fix this with the changes in this PR and also fixed a couple of other issues I noticed along the way.

The underlying problem was that Parse() was returning nil instead of a pointer to Config. This happened because the original code did:

var to *Config
err = json.Unmarshal(f.Data, &to)

Unfortunately fileb0x is still broken for me but this PR should at least fix the panic described above.

$ fileb0x ./defaults.yml 
panic: open /ab0x.go: permission denied

goroutine 1 [running]:
main.main()
    /home/opalmer/go/src/github.com/UnnoTed/fileb0x/main.go:146 +0x1a59

NOTE The above is a panic I introduced so I could show the line it's occurring on. log.Fatal() normally hides this information.