From 00f5076672d553f422d77726cbd2c2febb3b39da Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Thu, 12 Jul 2018 11:15:04 +0800 Subject: [PATCH] check empty buffer on read/write --- tls.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tls.go b/tls.go index 56400ce..0a51f28 100644 --- a/tls.go +++ b/tls.go @@ -201,6 +201,10 @@ func (c *Conn) Read(buf []byte) (n int, err error) { return } + if len(buf) == 0 { + return 0, nil + } + bufLen := len(buf) cbuf := C.malloc(C.size_t(bufLen)) defer C.free(cbuf) @@ -227,6 +231,12 @@ func (c *Conn) Write(buf []byte) (n int, err error) { if err != nil { return } + + // user may call Write(nil) to do handshake + if len(buf) == 0 { + return 0, nil + } + cbuf := C.CBytes(buf) defer C.free(cbuf)