From: Vladimír Čunát Date: Fri, 24 Feb 2017 10:26:28 +0000 (+0100) Subject: lua: do *not* truncate cache size to unsigned X-Git-Tag: v1.3.0~23^2~73^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=09f39925fbe52d675596c0d244314a8b07670a75;p=thirdparty%2Fknot-resolver.git lua: do *not* truncate cache size to unsigned ... and perform extra checks when converting from the floating-point number. --- diff --git a/daemon/bindings.c b/daemon/bindings.c index 26969087c..b6fdd7195 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -563,7 +564,14 @@ static int cache_open(lua_State *L) /* Select cache storage backend */ struct engine *engine = engine_luaget(L); - unsigned cache_size = lua_tonumber(L, 1); + + lua_Number csize_lua = lua_tonumber(L, 1); + if (!(csize_lua >= 8192 && csize_lua < SIZE_MAX)) { /* min. is basically arbitrary */ + format_error(L, "invalid cache size specified"); + lua_error(L); + } + size_t cache_size = csize_lua; + const char *conf = n > 1 ? lua_tostring(L, 2) : NULL; const char *uri = conf; const struct kr_cdb_api *api = cache_select(engine, &conf);