jfjallid / go-smb

A client library to interact with Windows RPC services such as MS-SRVS and MS-RRP.
MIT License
44 stars 9 forks source link

[bug] Unexpected Conn #12

Closed 9bie closed 9 months ago

9bie commented 9 months ago

I used example for my Project.

session, err := smb.NewConnection(options)
defer session.Close()

but some time, i got a error.

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

goroutine 17961 [running]:
github.com/jfjallid/go-smb/smb.(*Connection).Close(0xc000923340)
        C:/Users/my/go/pkg/mod/github.com/jfjallid/go-smb@v0.3.6/smb/session.go:1782 +0x12c
        .....

Then i add trhe code

session, err := smb.NewConnection(options)
defer function(){
        fmt.Println(session)
        session.Close()
}

i got this

&{0xc0005945a0 0xc0021135c0 <nil> 0 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 0 0 0 0xc000b0f680 0xc000b0f620 0xc00239ba40 0xc00239baa0 {0 0} <nil> false 0}
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x17c3a4c]

goroutine 17961 [running]:
github.com/jfjallid/go-smb/smb.(*Connection).Close(0xc000923340)
        C:/Users/my/go/pkg/mod/github.com/jfjallid/go-smb@v0.3.6/smb/session.go:1782 +0x12c

i think is no judgment for Connection.conn In session.go:Close():1723 if Connection.conn is nil

Can add a checksum for check Conn is not nil?

Although I don’t know yet how conn is nil.

jfjallid commented 9 months ago

Thanks for identifying a problem, I'll take a look.

jfjallid commented 9 months ago

I think the problem occurs when the tcp connection close before manually ending the session. One reason for this could be the idle timeout period after which a server will close the connection.

I've added a check in release v0.3.7 which should hopefully solve the issue.