Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic when config dir access denied #176

Merged
merged 1 commit into from
Sep 19, 2023
Merged

Conversation

oldshensheep
Copy link
Contributor

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.

func prepareDir(dir string) {
stat, err := os.Stat(dir)
if err != nil && os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatal("can not create config dir:", dir)
}
} else {
if !stat.IsDir() {
log.Fatal("path already exists, but not a dir:", dir)
}
}

@zu1k
Copy link
Owner

zu1k commented Sep 19, 2023

thanks

@zu1k zu1k merged commit f91569c into zu1k:master Sep 19, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants