Commit 9501173e authored by Levin Zimmermann's avatar Levin Zimmermann

go/neo/neonet: Fix segmentation violation in case handshake fails

Because 'err' was locally assigned inside the loop of 'DialLink' [1],
it was always 'nil' as a function return value, even when
'handshakeClient' actually returned an error. This lead to the
unfortunate situation that the function sometimes returned 'link=nil'
and 'err=nil', so that the function caller tried to access 'link'
attributes which lead to 'runtime error: invalid memory address or nil
pointer dereference'. This patch fixes this and now the function
correctly returns an error if the dialing fails.

[1] `peerConn, err := networker.Dial(ctx, addr)`
parent 5e90fc24
...@@ -319,9 +319,10 @@ func init() { ...@@ -319,9 +319,10 @@ func init() {
// DialLink connects to address on given network, performs NEO protocol // DialLink connects to address on given network, performs NEO protocol
// handshake and wraps the connection as NodeLink. // handshake and wraps the connection as NodeLink.
func DialLink(ctx context.Context, net xnet.Networker, addr string) (link *NodeLink, err error) { func DialLink(ctx context.Context, networker xnet.Networker, addr string) (link *NodeLink, err error) {
for _, enc := range dialEncTryOrder { for _, enc := range dialEncTryOrder {
peerConn, err := net.Dial(ctx, addr) var peerConn net.Conn
peerConn, err = networker.Dial(ctx, addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment