From 3d7180c36adb6b9be8f4bb9825d3e35eef146bf5 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 27 Feb 2017 15:23:05 +1100 Subject: extension.new: Factor out conf loading to own function --- src/openssl.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/openssl.c b/src/openssl.c index fa7dd79..900b909 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -4958,6 +4958,25 @@ static _Bool xe_new_isder(const char *value, _Bool *crit) { return 0; } /* xs_new_isder() */ +static CONF* loadconf(lua_State *L, int idx) { + CONF *conf; + size_t len; + const char *cdata = luaL_checklstring(L, idx, &len); + BIO *bio = getbio(L); + if (BIO_write(bio, cdata, len) < 0) + return NULL; + + if (!(conf = NCONF_new(NULL))) + return NULL; + + if (!NCONF_load_bio(conf, bio, NULL)) { + NCONF_free(conf); + return NULL; + } + + return conf; +} + static int xe_new(lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *value = luaL_checkstring(L, 2); @@ -4991,13 +5010,7 @@ static int xe_new(lua_State *L) { return 1; } - BIO *bio = getbio(L); - if (BIO_puts(bio, cdata) < 0) - goto error; - - if (!(conf = NCONF_new(NULL))) - goto error; - if (!NCONF_load_bio(conf, bio, NULL)) + if (!(conf = loadconf(L, 3))) goto error; ctx = &cbuf; -- cgit v1.2.3-55-g6feb