]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix empty strings import
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 23 Sep 2022 19:43:39 +0000 (20:43 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 23 Sep 2022 19:43:39 +0000 (20:43 +0100)
Issue: #4281

contrib/libucl/lua_ucl.c

index 88cdf3664f4a6a0767a862c84c87ff56f286c8c2..0d934b771e067b5b74ab14f5914a585fce82abdf 100644 (file)
@@ -484,7 +484,16 @@ ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags)
                str = lua_tolstring (L, idx, &sz);
 
                if (str) {
-                       obj = ucl_object_fromstring_common (str, sz, flags);
+                       /*
+                        * ucl_object_fromstring_common has a `logic` to use strlen if sz is zero
+                        * which is totally broken...
+                        */
+                       if (sz > 0) {
+                               obj = ucl_object_fromstring_common(str, sz, flags);
+                       }
+                       else {
+                               obj = ucl_object_fromstring_common("", sz, flags);
+                       }
                }
                else {
                        obj = ucl_object_typed_new (UCL_NULL);
@@ -511,7 +520,12 @@ ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags)
                        struct _rspamd_lua_text *t = lua_touserdata (L, idx);
 
                        if (t) {
-                               obj = ucl_object_fromstring_common(t->start, t->len, 0);
+                               if (t->len >0) {
+                                       obj = ucl_object_fromstring_common(t->start, t->len, 0);
+                               }
+                               else {
+                                       obj = ucl_object_fromstring_common("", 0, 0);
+                               }
 
                                /* Binary text */
                                if (t->flags & (1u << 5u)) {