Skip to content

Commit

Permalink
fix three possible half-opened connections
Browse files Browse the repository at this point in the history
  • Loading branch information
madper committed Feb 9, 2015
1 parent ae3a7b8 commit 55e1458
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion client/main.go
Expand Up @@ -50,7 +50,11 @@ func handleTCPConnection(c net.Conn) {
logger.Debugf("addressType: %d\n", addressType)
logger.Debugf("port: %d\n", port)

c.Write(reqAnswer)
_, err = c.Write(reqAnswer)
if err != nil {
logger.Warningf("write req answer failed: %s", err)
return
}

proxyAgent, err := tunnel.NewClient(lc.Tunnel, lc.Server, lc.ServerPort, lc.MasterKey, lc.EncryptMethod, lc.Password, logger)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions client/socks5.go
Expand Up @@ -29,8 +29,8 @@ func handShake(c net.Conn) error {
return fmt.Errorf("Protocol mismatch: %d", protoVersion)
}

c.Write(handShakeAnswer)
return nil
_, err = c.Write(handShakeAnswer)
return err
}

// commandCode, addressType, address, port, err
Expand Down Expand Up @@ -85,8 +85,8 @@ func parseReq(c net.Conn) (byte, byte, []byte, uint16, error) {
}

var port uint16
binary.Read(r, binary.BigEndian, &port)
err = binary.Read(r, binary.BigEndian, &port)

// commandCode, addressType, address, port, err
return commandCode, addressType, address.Bytes(), port, nil
return commandCode, addressType, address.Bytes(), port, err
}

0 comments on commit 55e1458

Please sign in to comment.