]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Check number of arguments
authorAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 18 Oct 2018 09:31:27 +0000 (12:31 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 14 Nov 2018 12:11:00 +0000 (14:11 +0200)
src/lib-lua/dlua-dovecot.c

index d6d8b49d88f4274981e0e0df2c25bac784fbf0ec..6fcf455c69f411f28f09ec7e912b711a9c047569 100644 (file)
@@ -37,6 +37,7 @@ static void dlua_push_event_passthrough(struct dlua_script *script,
 static int dlua_event_pt_append_log_prefix(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *prefix = luaL_checkstring(script->L, 2);
 
@@ -50,6 +51,7 @@ static int dlua_event_pt_append_log_prefix(lua_State *L)
 static int dlua_event_pt_replace_log_prefix(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *prefix = luaL_checkstring(script->L, 2);
 
@@ -63,6 +65,7 @@ static int dlua_event_pt_replace_log_prefix(lua_State *L)
 static int dlua_event_pt_set_name(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
 
@@ -77,6 +80,7 @@ static int dlua_event_pt_set_name(lua_State *L)
 static int dlua_event_pt_set_always_log_source(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 1);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
 
        event->set_always_log_source();
@@ -89,6 +93,7 @@ static int dlua_event_pt_set_always_log_source(lua_State *L)
 static int dlua_event_pt_add_str(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        const char *value = luaL_checkstring(script->L, 3);
@@ -103,6 +108,7 @@ static int dlua_event_pt_add_str(lua_State *L)
 static int dlua_event_pt_add_int(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        lua_Integer value = luaL_checkinteger(script->L, 3);
@@ -117,6 +123,7 @@ static int dlua_event_pt_add_int(lua_State *L)
 static int dlua_event_pt_add_timeval(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        /* this is time in seconds */
@@ -135,6 +142,7 @@ static int dlua_event_pt_add_timeval(lua_State *L)
 static int dlua_event_pt_inc_int(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        lua_Integer value = luaL_checkinteger(script->L, 3);
@@ -149,6 +157,7 @@ static int dlua_event_pt_inc_int(lua_State *L)
 static int dlua_event_pt_log_debug(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -162,6 +171,7 @@ static int dlua_event_pt_log_debug(lua_State *L)
 static int dlua_event_pt_log_info(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -175,6 +185,7 @@ static int dlua_event_pt_log_info(lua_State *L)
 static int dlua_event_pt_log_warning(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -188,6 +199,7 @@ static int dlua_event_pt_log_warning(lua_State *L)
 static int dlua_event_pt_log_error(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event_passthrough *event = dlua_check_event_passthrough(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -242,6 +254,7 @@ void dlua_push_event(struct dlua_script *script, struct event *event)
 static int dlua_event_append_log_prefix(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event *event = dlua_check_event(script, 1);
        const char *prefix = luaL_checkstring(script->L, 2);
 
@@ -255,6 +268,7 @@ static int dlua_event_append_log_prefix(lua_State *L)
 static int dlua_event_replace_log_prefix(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event *event = dlua_check_event(script, 1);
        const char *prefix = luaL_checkstring(script->L, 2);
 
@@ -268,6 +282,7 @@ static int dlua_event_replace_log_prefix(lua_State *L)
 static int dlua_event_set_name(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event *event = dlua_check_event(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
 
@@ -282,6 +297,7 @@ static int dlua_event_set_name(lua_State *L)
 static int dlua_event_set_always_log_source(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 1);
        struct event *event = dlua_check_event(script, 1);
 
        event_set_always_log_source(event);
@@ -294,6 +310,7 @@ static int dlua_event_set_always_log_source(lua_State *L)
 static int dlua_event_add_str(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event *event = dlua_check_event(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        const char *value = luaL_checkstring(script->L, 3);
@@ -308,6 +325,7 @@ static int dlua_event_add_str(lua_State *L)
 static int dlua_event_add_int(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event *event = dlua_check_event(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        lua_Integer value = luaL_checkinteger(script->L, 3);
@@ -322,6 +340,7 @@ static int dlua_event_add_int(lua_State *L)
 static int dlua_event_add_timeval(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event *event = dlua_check_event(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        /* this is time in seconds */
@@ -340,6 +359,7 @@ static int dlua_event_add_timeval(lua_State *L)
 static int dlua_event_inc_int(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 3);
        struct event *event = dlua_check_event(script, 1);
        const char *name = luaL_checkstring(script->L, 2);
        lua_Integer value = luaL_checkinteger(script->L, 3);
@@ -354,6 +374,7 @@ static int dlua_event_inc_int(lua_State *L)
 static int dlua_event_log_debug(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event *event = dlua_check_event(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -367,6 +388,7 @@ static int dlua_event_log_debug(lua_State *L)
 static int dlua_event_log_info(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event *event = dlua_check_event(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -380,6 +402,7 @@ static int dlua_event_log_info(lua_State *L)
 static int dlua_event_log_warning(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event *event = dlua_check_event(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -393,6 +416,7 @@ static int dlua_event_log_warning(lua_State *L)
 static int dlua_event_log_error(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        struct event *event = dlua_check_event(script, 1);
        const char *str = luaL_checkstring(script->L, 2);
 
@@ -406,6 +430,7 @@ static int dlua_event_log_error(lua_State *L)
 static int dlua_event_passthrough_event(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 1);
        struct event *event = dlua_check_event(script, 1);
        struct event_passthrough *e = event_create_passthrough(event);
        dlua_push_event_passthrough(script, e);
@@ -424,6 +449,7 @@ static int dlua_event_gc(lua_State *L)
 static int dlua_event_new(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS_IN(script, 0, 1);
        lua_Debug ar;
        struct event *event, *parent = script->event;
        if (lua_gettop(script->L) == 1)
@@ -471,6 +497,7 @@ static void dlua_event_register(struct dlua_script *script){
 static int dlua_i_debug(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 1);
        const char *msg = luaL_checkstring(script->L, 1);
        i_debug("%s", msg);
        return 0;
@@ -479,6 +506,7 @@ static int dlua_i_debug(lua_State *L)
 static int dlua_i_info(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 1);
        const char *msg = luaL_checkstring(script->L, 1);
        i_info("%s", msg);
        return 0;
@@ -487,6 +515,7 @@ static int dlua_i_info(lua_State *L)
 static int dlua_i_warning(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 1);
        const char *msg = luaL_checkstring(script->L, 1);
        i_warning("%s", msg);
        return 0;
@@ -495,6 +524,7 @@ static int dlua_i_warning(lua_State *L)
 static int dlua_i_error(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 1);
        const char *msg = luaL_checkstring(script->L, 1);
        i_error("%s", msg);
        return 0;
@@ -503,6 +533,7 @@ static int dlua_i_error(lua_State *L)
 static int dlua_has_flag(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        /* we rather deal with unsigned value here */
        lua_Integer value = luaL_checkinteger(script->L, 1);
        lua_Integer flag = luaL_checkinteger(script->L, 2);
@@ -514,6 +545,7 @@ static int dlua_has_flag(lua_State *L)
 static int dlua_set_flag(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        lua_Integer value = luaL_checkinteger(script->L, 1);
        lua_Integer flag = luaL_checkinteger(script->L, 2);
 
@@ -524,6 +556,7 @@ static int dlua_set_flag(lua_State *L)
 static int dlua_clear_flag(lua_State *L)
 {
        struct dlua_script *script = dlua_script_from_state(L);
+       DLUA_REQUIRE_ARGS(script, 2);
        lua_Integer value = luaL_checkinteger(script->L, 1);
        lua_Integer flag = luaL_checkinteger(script->L, 2);