gpt4 book ai didi

go - 访问挂载目录时出现分段冲突

转载 作者:数据小太阳 更新时间:2023-10-29 03:20:53 26 4
gpt4 key购买 nike

访问挂载的网络共享时出现分段违规代码=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




最佳答案

panic: runtime error: invalid memory address or nil pointer dereference

文档提到如果发生错误,info 可能为 nil:

Package filepath

import "path/filepath"

type WalkFunc

In the case of an error, the info argument will be nil.

type WalkFunc func(path string, info os.FileInfo, err error) error

因此,为了避免 panic ,您应该在尝试使用它之前检查 info 参数是否为 nil。

关于go - 访问挂载目录时出现分段冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54191366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com