diff mbox series

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

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

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(-)

Comments

Jo-Philipp Wich March 15, 2020, 7:50 p.m. UTC | #1
Hi,

applied with slight changes in
https://git.openwrt.org/?p=project/ubus.git;a=commitdiff;h=171469e3138cce191892e20b6fd35b52c9368064
- thanks!

~ Jo
diff mbox series

Patch

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: