From 0415e2c02882e9f0c7d7a95ef0a23fe4ea4d14ab Mon Sep 17 00:00:00 2001 From: serg3295 Date: Mon, 17 Jul 2023 12:39:31 +0300 Subject: [PATCH] fix(mqtt): adds parameter checking to nil --- components/modules/mqtt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/modules/mqtt.c b/components/modules/mqtt.c index 7e7f534b1..2a456ce6e 100644 --- a/components/modules/mqtt.c +++ b/components/modules/mqtt.c @@ -368,14 +368,19 @@ static int mqtt_connect(lua_State* L) { if (is_mqtt_uri || is_mqtts_uri) return luaL_error(L, "port arg must be nil if giving full uri"); port = luaL_checknumber(L, n); + n++; + } else if (lua_type(L, n) == LUA_TNIL) { + n++; } - n++; if (lua_isnumber(L, n)) { if (is_mqtt_uri || is_mqtts_uri) return luaL_error(L, "secure on/off determined by uri"); secure = !!luaL_checkinteger(L, n); + n++; + } else if (lua_type(L, n) == LUA_TNIL) { + n++; } else { if (lua_istable(L, n)) { secure = true; @@ -396,9 +401,10 @@ static int mqtt_connect(lua_State* L) { luaX_set_ref(L, -1, &mqtt_context->client_key_pem); } lua_pop(L, 1); + // + n++; } } - n++; if (lua_isnumber(L, n)) { reconnect = !!luaL_checkinteger(L, n);