summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlin Nastac <alin.nastac@gmail.com>2020-02-03 13:58:04 +0100
committerPetr Štetiar <ynezz@true.cz>2021-06-03 10:00:50 +0200
commit9ec9cfc6574a197ea934489de056594f44088352 (patch)
tree1b21638351b619614ec04966e0a17e959c7fd630
parent041c9d1c052bb4936fd03240f7d0dd64aedda972 (diff)
downloadubus-9ec9cfc6574a197ea934489de056594f44088352.tar.gz
lua: avoid truncation of large numeric values
If the Lua number exceeds the maximum value representable by an unsigned 32bit integer, store it in an unsigned 64bit integer field instead. Signed-off-by: Alin Nastac <alin.nastac@gmail.com> [align code style, reword commit message] Signed-off-by: Jo-Philipp Wich <jo@mein.io> (cherry picked from commit 171469e3138cce191892e20b6fd35b52c9368064)
-rw-r--r--lua/ubus.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lua/ubus.c b/lua/ubus.c
index 86dcc50..e2bb081 100644
--- a/lua/ubus.c
+++ b/lua/ubus.c
@@ -196,7 +196,10 @@ 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: