From: Adrian Frances <adrian.fran...@netduma.com>

According to the lua man page for lua_next, it is not
advised to call lua_tolstring when iterating through a
table with lua_next.

When iterating a table in ubus_lua_format_blob_array,
we end up calling lua_tostring, which inside calls
lua_tolstring, converting all non-string keys to a key
format, even for the caller.

This patch fixes the issue by restoring the original key

Signed-off-by: Adrian Frances <adrian.fran...@netduma.com>
---
 lua/ubus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lua/ubus.c b/lua/ubus.c
index e2bb081..d949aea 100644
--- a/lua/ubus.c
+++ b/lua/ubus.c
@@ -184,7 +184,9 @@ ubus_lua_format_blob(lua_State *L, struct blob_buf *b, bool 
table)
 {
        void *c;
        bool rv = true;
-       const char *key = table ? lua_tostring(L, -2) : NULL;
+       lua_pushvalue(L,-2);
+       const char *key = table ? lua_tostring(L, -1) : NULL;
+       lua_pop(L,1);
 
        switch (lua_type(L, -1))
        {
-- 
2.25.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to