mirror of
https://github.com/brunoos/luasec.git
synced 2024-11-07 22:18:27 +01:00
context: Don't leak EC_KEY in set_curve()
SSL_CTX_set_tmp_ecdh() takes a reference to the provided key. ==8323== 1,044 (56 direct, 988 indirect) bytes in 1 blocks are definitely lost in loss record 611 of 631 ==8323== at 0x4C2935B: malloc (vg_replace_malloc.c:270) ==8323== by 0x5E05D9F: CRYPTO_malloc (mem.c:308) ==8323== by 0x5E59859: EC_KEY_new (ec_key.c:75) ==8323== by 0x5E59974: EC_KEY_new_by_curve_name (ec_key.c:96) ==8323== by 0x4E395A7: set_curve (context.c:261) ...
This commit is contained in:
parent
a344f58b20
commit
3fb33cdc4e
@ -507,15 +507,22 @@ static int set_curve(lua_State *L)
|
||||
#else
|
||||
static int set_curve(lua_State *L)
|
||||
{
|
||||
long ret;
|
||||
SSL_CTX *ctx = lsec_checkcontext(L, 1);
|
||||
const char *str = luaL_checkstring(L, 2);
|
||||
EC_KEY *key = find_ec_key(str);
|
||||
|
||||
if (!key) {
|
||||
lua_pushboolean(L, 0);
|
||||
lua_pushstring(L, "elliptic curve not supported");
|
||||
return 2;
|
||||
}
|
||||
if (!SSL_CTX_set_tmp_ecdh(ctx, key)) {
|
||||
|
||||
ret = SSL_CTX_set_tmp_ecdh(ctx, key);
|
||||
/* SSL_CTX_set_tmp_ecdh takes its own reference */
|
||||
EC_KEY_free(key);
|
||||
|
||||
if (!ret) {
|
||||
lua_pushboolean(L, 0);
|
||||
lua_pushstring(L, "error setting elliptic curve");
|
||||
return 2;
|
||||
|
Loading…
Reference in New Issue
Block a user