oltdaniel / caddy-ipinfo-free

integrate the free ipinfo database into caddy
MIT License
10 stars 1 forks source link

Segmentation Violation during Caddyfile validation #3

Closed ZeroAnarchy closed 1 month ago

ZeroAnarchy commented 1 month ago

CMD: sudo caddy validate --config /etc/caddy/Caddyfile

Output

``` 2024/08/16 08:46:33.622 INFO using config from file {"file": "/etc/caddy/Caddyfile"} 2024/08/16 08:46:33.643 INFO adapted config to JSON {"adapter": "caddyfile"} ... {"level":"info","ts":1723797993.6476502,"logger":"caddy.states.ipinfo-free","msg":"gocron: new scheduler created"} {"level":"info","ts":1723797993.6478193,"logger":"caddy.states.ipinfo-free","msg":"ipinfo configured to use","database_type":"country_asn.mmdb"} ... panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0xb8 pc=0xcf7cf77e152] goroutine 1 [running]: github.com/oschwald/maxminddb-golang.(*Reader).Close(0xc000b1c580?) github.com/oschwald/maxminddb-golang@v1.13.1/reader_mmap.go:57 +0x12 github.com/oltdaniel/caddy-ipinfo-free.(*IPInfoFreeState).Cleanup(0xc000688300) github.com/oltdaniel/caddy-ipinfo-free@v0.0.0-20240814172312-af3db66df9e1/state.go:395 +0x46 github.com/caddyserver/caddy/v2.NewContext.func1() github.com/caddyserver/caddy/v2@v2.8.4/context.go:73 +0x162 github.com/caddyserver/caddy/v2.Validate(0xc000746060) github.com/caddyserver/caddy/v2@v2.8.4/caddy.go:692 +0xb6 github.com/caddyserver/caddy/v2/cmd.cmdValidateConfig({0x0?}) github.com/caddyserver/caddy/v2@v2.8.4/cmd/commandfuncs.go:547 +0x155 github.com/caddyserver/caddy/v2/cmd.init.1.func8.WrapCommandFuncForCobra.1(0xc0005e9b08, {0xcf7cfc893df?, 0x4?, 0xcf7cfc8939b?}) github.com/caddyserver/caddy/v2@v2.8.4/cmd/cobra.go:137 +0x2f github.com/spf13/cobra.(*Command).execute(0xc0005e9b08, {0xc0003edaa0, 0x2, 0x2}) github.com/spf13/cobra@v1.8.1/command.go:985 +0xaca github.com/spf13/cobra.(*Command).ExecuteC(0xcf7d18d0e40) github.com/spf13/cobra@v1.8.1/command.go:1117 +0x3ff github.com/spf13/cobra.(*Command).Execute(...) github.com/spf13/cobra@v1.8.1/command.go:1041 github.com/caddyserver/caddy/v2/cmd.Main() github.com/caddyserver/caddy/v2@v2.8.4/cmd/main.go:75 +0x1d8 main.main() caddy/main.go:23 +0xf ```

Perhaps the module is trying to close uninitialized mmdb file database, because no database is opened during config validation (especially since there is no *.mmdb file on disk at all), but Cleanup() function is executed anyway.

oltdaniel commented 1 month ago

Well spotted. Never ran into that use case. Very likely this is the issue of having a nil pointer there.

I will add a condition the prevent this, later today.

oltdaniel commented 1 month ago

Fixed now even though I mentioned the wrong issue in the commit (happens when you commit too fast). https://github.com/oltdaniel/caddy-ipinfo-free/commit/e4887beb7ae89bbd1eb6849ac2b05cd512e6ef4b