Sftp Client and Segmentation Fault

Hello
I read somewhere there are similar bugs like this, but I am not sure about.

srcFile, err := sftpClient.Open(remotePath) this is a *sftp.File, not os.File
srcFileInfo, err2 := srcFile.Stat()

On calling STAT I get the following error and I can’t resolve it by myself

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x556d7d]

goroutine 25 [running]:
github.com/pkg/sftp.(*File).Stat(0x0)
        /home/fabio/go/pkg/mod/github.com/pkg/sftp@v1.13.4/client.go:1403 +0x1d
main/myscript/goutil.downloadFile(0x0, 0xc00007f0e0, {0x7ffff08bc016, 0x17}, {0xc0001cba40, 0x48})
        /home/fabio/golang-repo/main/myscript/goutil/Ssh.go:78 +0x7b
created by main/myscript/goutil.GetRemoteDirFiles
        /home/fabio/golang-repo/main/myscript/goutil/Ssh.go:69 +0x333

Can you help me, please?

Thanks in advanced

What is the value of err?

From the code you have shown it seems as if you weren’t checking any errors returned by sftpClient.Open().

You should therefore definitely check those, and perhaps also log the value of srcFile! Only if both are nil at the same time, we can consider upstream bugs.

3 Likes

oh Ok nevermind
Even if it could be an error, it was not the best practice to use that code.
After having changed some stuff I could reach my purpose anyway.

Thank you