Skip to content

Commit e018055

Browse files
committed
fixed issue where go/C pointer sharing rules were being violated (go 1.6+).
1 parent 9934c10 commit e018055

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

Diff for: ctx.go

100644100755
+21-21
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ static long SSL_CTX_set_tlsext_servername_callback_not_a_macro(SSL_CTX* ctx, voi
7474
return SSL_CTX_set_tlsext_servername_callback(ctx, fp);
7575
}
7676
77-
typedef struct TlsServernameData {
77+
typedef struct TlsExtData {
7878
void *go_ctx;
7979
SSL_CTX *ctx;
8080
void *arg;
81-
} TlsServernameData;
81+
} TlsExtData;
8282
83-
extern int callServerNameCb(SSL* ssl, int ad, void* arg);
83+
extern int callServernameCb(SSL* ssl, int ad, void* arg);
8484
8585
static int call_go_servername(SSL* ssl, int ad, void* arg) {
86-
return callServerNameCb(ssl, ad, arg);
86+
return callServernameCb(ssl, ad, arg);
8787
}
8888
89-
static int servername_gateway(TlsServernameData* cw) {
89+
static int servername_gateway(TlsExtData* cw) {
9090
SSL_CTX* ctx = cw->ctx;
9191
//TODO: figure out what to do with return codes. The first isn't 0
9292
SSL_CTX_set_tlsext_servername_callback(ctx, call_go_servername);
93-
SSL_CTX_set_tlsext_servername_arg(ctx, cw);
93+
SSL_CTX_set_tlsext_servername_arg(ctx, cw.arg);
9494
return 0;
9595
}
9696
@@ -141,13 +141,13 @@ var (
141141
)
142142

143143
type Ctx struct {
144-
ctx *C.SSL_CTX
145-
cert *Certificate
146-
chain []*Certificate
147-
key PrivateKey
148-
verify_cb VerifyCallback
149-
servername_cb ServerNameCallback
150-
ted C.TlsServernameData
144+
ctx *C.SSL_CTX
145+
cert *Certificate
146+
chain []*Certificate
147+
key PrivateKey
148+
verify_cb VerifyCallback
149+
//servername_cb ServerNameCallback
150+
servername_cb func(ssl Conn, ad int, arg unsafe.Pointer) int
151151
}
152152

153153
//export get_ssl_ctx_idx
@@ -634,11 +634,11 @@ func (c *Ctx) SessGetCacheSize() int {
634634

635635
// Set SSL_CTX_set_tlsext_servername_callback
636636
// https://www.openssl.org/docs/manmaster/ssl/???
637-
type ServerNameCallback func(ssl Conn, ad int, arg unsafe.Pointer) int
637+
//type ServerNameCallback func(ssl *C.SSL, ad C.int, arg unsafe.Pointer) int
638638

639-
//export callServerNameCb
640-
func callServerNameCb(ssl *C.SSL, ad C.int, arg unsafe.Pointer) C.int {
641-
var ted *C.TlsServernameData = (*C.TlsServernameData)(arg)
639+
//export callServernameCb
640+
func callServernameCb(ssl *C.SSL, ad C.int, arg unsafe.Pointer) C.int {
641+
var ted *C.TlsExtData = (*C.TlsExtData)(arg)
642642
goCtx := (*Ctx)(ted.go_ctx)
643643

644644
//setup a dummy Conn so we can associate a SSL_CTX from user callback
@@ -650,13 +650,13 @@ func callServerNameCb(ssl *C.SSL, ad C.int, arg unsafe.Pointer) C.int {
650650
return C.int(ret)
651651
}
652652

653-
func (c *Ctx) SetTlsExtServerNameCallback(cb func(ssl Conn, ad int, arg unsafe.Pointer) int,
654-
arg unsafe.Pointer) int {
653+
//func (c *Ctx) SetTlsExtServerNameCallback(cb ServerNameCallback) int {
654+
func (c *Ctx) SetTlsExtServerNameCallback(cb func(ssl Conn, ad int, arg unsafe.Pointer) int, arg unsafe.Pointer) int {
655655
c.servername_cb = cb
656-
c.ted = C.TlsServernameData{
656+
cw := C.TlsExtData{
657657
go_ctx: unsafe.Pointer(c),
658658
ctx: c.ctx,
659659
arg: arg,
660660
}
661-
return int(C.servername_gateway(&c.ted))
661+
return int(C.servername_gateway(&cw))
662662
}

0 commit comments

Comments
 (0)