]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: Don't strip last non-LWS char in hlua_pushstrippedstring()
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 3 Mar 2021 18:36:51 +0000 (19:36 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 3 Mar 2021 18:48:12 +0000 (19:48 +0100)
hlua_pushstrippedstring() function strips leading and trailing LWS
characters. But the result length it too short by 1 byte. Thus the last
non-LWS character is stripped. Note that a string containing only LWS
characters resulting to a stipped string with an invalid length (-1). This
leads to a lua runtime error.

This bug was reported in the issue #1155. It must be backported as far as
1.7.

src/hlua_fcn.c

index c2d26817ac3e0f4699c739c28c304f42cbf45e81..46a807e58f4ef1da5a1c118285fde2deedc37be1 100644 (file)
@@ -172,12 +172,13 @@ int hlua_fcn_pushfield(lua_State *L, struct field *field)
 const char *hlua_pushstrippedstring(lua_State *L, const char *str)
 {
        const char *p;
-       const char *e;
+       int l;
 
        for (p = str; HTTP_IS_LWS(*p); p++);
-       for (e = p + strlen(p) - 1; e > p && HTTP_IS_LWS(*e); e--);
 
-       return lua_pushlstring(L, p, e - p);
+       for (l = strlen(p); l && HTTP_IS_LWS(p[l-1]); l--);
+
+       return lua_pushlstring(L, p, l);
 }
 
 /* The three following functions are useful for adding entries