From d4ea2d12f373ef95e0b790b487dde3a374d1b988 Mon Sep 17 00:00:00 2001 From: Bruno Silvestre Date: Mon, 10 Sep 2018 10:49:18 -0300 Subject: [PATCH] Update reference to Lua state prior to handshake The Lua thread that creates the context is saved to be used for accessing callback related data. However that thread may become garbage and its memory could be overwritten with anything if the handshake happens later, in a different thread. Fixes #75 Thanks @Zash --- src/ssl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ssl.c b/src/ssl.c index 4dd4686..676ed38 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -382,9 +382,11 @@ static int meth_setfd(lua_State *L) */ static int meth_handshake(lua_State *L) { + int err; p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection"); - int err = handshake(ssl); p_context ctx = (p_context)SSL_CTX_get_app_data(SSL_get_SSL_CTX(ssl->ssl)); + ctx->L = L; + err = handshake(ssl); if (ctx->dh_param) { DH_free(ctx->dh_param); ctx->dh_param = NULL;