访问已挂载的网络共享时出现段违反代码= 0x1错误
运行golang应用程序(PwnDelorian)的Ubuntu服务器崩溃。检查目录的权限,那里一切似乎都很好。
fileList := []FileStruct{}
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
fileList = append(fileList, FileStruct{f.Name(), path})
return nil
})
if err != nil {
return nil, err
}
return fileList, nil
}
> panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x6482bf]
>goroutine 1 [running]:
main.getAllFilesInDirectory.func1(0xc42031d950, 0x49, 0x0, 0x0, 0x71ea20, 0xc4202ba990, 0x0, 0x0)
/home/jim/go/src/PwnDelorean/filesystem.go:42 +0x2f
path/filepath.walk(0xc42030fa80, 0x3c, 0x721ec0, 0xc420357930, 0xc42009b730, 0x0, 0x0)
/usr/lib/go-1.10/src/path/filepath/path.go:377 +0x20d
path/filepath.walk(0xc42033eab0, 0x24, 0x721ec0, 0xc420356c30, 0xc42009b730, 0x0, 0x0)
/usr/lib/go-1.10/src/path/filepath/path.go:381 +0x2c2
path/filepath.walk(0xc420313260, 0x16, 0x721ec0, 0xc420356820, 0xc42009b730, 0x0, 0x0)
/usr/lib/go-1.10/src/path/filepath/path.go:381 +0x2c2
path/filepath.walk(0x7ffd2448320a, 0x11, 0x721ec0, 0xc4200a1d40, 0xc42009b730, 0x0, 0x10)
/usr/lib/go-1.10/src/path/filepath/path.go:381 +0x2c2
path/filepath.Walk(0x7ffd2448320a, 0x11, 0xc42009b730, 0x0, 0x4982c4)
/usr/lib/go-1.10/src/path/filepath/path.go:403 +0x106
main.getAllFilesInDirectory(0x7ffd2448320a, 0x11, 0x11, 0x0, 0xc4200a1ba0, 0xc42006bdf0, 0x497b5d)
/home/jim/go/src/PwnDelorean/filesystem.go:41 +0xc4
main.startFileSystemScan()
/home/jim/go/src/PwnDelorean/filesystem.go:129 +0x4e
main.main()
/home/jim/go/src/PwnDelorean/main.go:136 +0x91
答案 0 :(得分:0)
panic: runtime error: invalid memory address or nil pointer dereference
从文档开始:
导入“路径/文件路径”
在发生错误的情况下,
info
参数将为nil
。type WalkFunc func(path string, info os.FileInfo, err error) error