zu1k / nali

An offline tool for querying IP geographic information and CDN provider. 一个查询IP地理信息和CDN服务提供商的离线终端工具.
https://github.com/zu1k/nali
MIT License
3.74k stars 340 forks source link

fix: panic when config dir access denied #176

Closed oldshensheep closed 11 months ago

oldshensheep commented 11 months ago

nali will panic when ConfigDir is not accessible

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x4b8fa2]

goroutine 1 [running]:
github.com/zu1k/nali/internal/constant.prepareDir({0xc000022f40, 0x35})
        github.com/zu1k/nali/internal/constant/path.go:45 +0xe2
github.com/zu1k/nali/internal/constant.init.0()
        github.com/zu1k/nali/internal/constant/path.go:32 +0x1f8

L45 stat is possible nil, we need to check other errs to make sure stat is not nil. In my case, the err is Access is denied. https://github.com/zu1k/nali/blob/20a0de63f1eb447bf22fdbdd0609c3b2abc481f5/internal/constant/path.go#L38-L48

zu1k commented 11 months ago

thanks