[OpenWrt-Devel] ubus: lua binding does not allow a reply with 64 bit numbers
diff mbox series

Message ID 1580734684-16319-1-git-send-email-alin.nastac@gmail.com
State New
Headers show
Series
  • [OpenWrt-Devel] ubus: lua binding does not allow a reply with 64 bit numbers
Related show

Commit Message

Alin Năstac Feb. 3, 2020, 12:58 p.m. UTC
Numbers originated from lua bindings get explicitly truncated to 32 bit.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
---
 lua/ubus.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/lua/ubus.c b/lua/ubus.c
index 86dcc50..aa01ac9 100644
--- a/lua/ubus.c
+++ b/lua/ubus.c
@@ -196,7 +196,11 @@  ubus_lua_format_blob(lua_State *L, struct blob_buf *b, bool table)
 	case LUA_TINT:
 #endif
 	case LUA_TNUMBER:
-		blobmsg_add_u32(b, key, (uint32_t)lua_tointeger(L, -1));
+		if((uint64_t)lua_tonumber(L, -1) > INT_MAX) {
+			blobmsg_add_u64(b, key, (uint64_t)lua_tonumber(L, -1));
+		} else {
+			blobmsg_add_u32(b, key, (uint32_t)lua_tointeger(L, -1));
+		}
 		break;
 
 	case LUA_TSTRING: