From 8db626a560b008c699eeed222d2b56a30a79e7a8 Mon Sep 17 00:00:00 2001 From: paul cannon Date: Thu, 15 May 2014 12:54:20 -0600 Subject: [PATCH] use CString with SetTlsExtHostName i guess we can't rely on there being a null byte after the memory for a byte array. in retrospect it seems really stupid to think there would be. go me Change-Id: I35ab6704cefbfbde064906aa682985574cb7e034 --- conn.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index 1c2d8879..61c02037 100644 --- a/conn.go +++ b/conn.go @@ -16,6 +16,7 @@ package openssl +// #include // #include // #include // #include @@ -490,8 +491,8 @@ func (c *Conn) UnderlyingConn() net.Conn { } func (c *Conn) SetTlsExtHostName(name string) error { - bname := []byte(name) - cname := (*C.char)(unsafe.Pointer(&bname[0])) + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) runtime.LockOSThread() defer runtime.UnlockOSThread() if C.SSL_set_tlsext_host_name_not_a_macro(c.ssl, cname) == 0 {