From 79416cbd7abe63265d92f4c4dc0bc51a7cb2cf11 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Fri, 24 Sep 2021 14:51:44 +0200 Subject: [PATCH] BUG/MINOR: httpclient/lua: return an error on argument check src/hlua.c:7074:6: error: variable 'url_str' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] if (lua_type(L, -1) == LUA_TSTRING) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/hlua.c:7079:36: note: uninitialized use occurs here hlua_hc->hc->req.url = istdup(ist(url_str)); ^~~~~~~ Return an error on the stack if the argument is not a string. --- src/hlua.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index b3f792c3e..e99796489 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -7070,9 +7070,11 @@ __LJMP static int hlua_httpclient_get(lua_State *L) if (lua_gettop(L) < 1 || lua_gettop(L) > 2) WILL_LJMP(luaL_error(L, "'get' needs between 1 or 2 arguments")); + if (lua_type(L, -1) != LUA_TSTRING) + WILL_LJMP(luaL_error(L, "'get' takes an URL as a string arugment")); + /* arg 1: URL */ - if (lua_type(L, -1) == LUA_TSTRING) - url_str = lua_tostring(L, -1); + url_str = lua_tostring(L, -1); hlua_hc = hlua_checkhttpclient(L, 1);