]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua: do *not* truncate cache size to unsigned
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 24 Feb 2017 10:26:28 +0000 (11:26 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 24 Feb 2017 11:36:23 +0000 (12:36 +0100)
... and perform extra checks when converting from the floating-point
number.

daemon/bindings.c

index 26969087cb1bd1b3af5417546e390ad9cc37cb7e..b6fdd71956091298eafceb24ad58b7f81f396d56 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <assert.h>
+#include <stdint.h>
 #include <uv.h>
 #include <contrib/cleanup.h>
 #include <libknot/descriptor.h>
@@ -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);