]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: httpclient/lua: return an error on argument check
authorWilliam Lallemand <wlallemand@haproxy.org>
Fri, 24 Sep 2021 12:51:44 +0000 (14:51 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Fri, 24 Sep 2021 12:57:15 +0000 (14:57 +0200)
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

index b3f792c3eb80c48462fb99971ffe95a8a74f40a6..e997964895f200f9bf73469aa1f5634cfa94eb2f 100644 (file)
@@ -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);