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
This commit is contained in:
paul cannon 2014-05-15 12:54:20 -06:00
parent 1738273569
commit 8db626a560

View File

@ -16,6 +16,7 @@
package openssl
// #include <stdlib.h>
// #include <openssl/ssl.h>
// #include <openssl/conf.h>
// #include <openssl/err.h>
@ -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 {