libubus-lua: Wrong conversion for negative numbers on 64bit systems

Florian Eckert fe at
Tue Jan 11 04:02:14 PST 2022


The commit [1] added a regression for negative numbers in the ubus lua 
binding on 64bit systems.
This is was also backported to openwrt-19.07 branch with this commit 

I have noticed this on my Apu3 x86_64 system and I do not see this error 
on my 32 bit system.
I assume that this error occurs with every 64bit system.

This issue can be reproduced in the following way:

LUA Test-Script (lua /root/test.lua):
local util = require "luci.util"
local status = util.ubus("luci.test", "dump", {})

LUA Test-Service (lua /root/luci.test):

#!/usr/bin/env lua

local ubus = require "ubus"
local uloop = require "uloop"


local conn = ubus.connect()
if not conn then
         error("Failed to connect to ubus")

local name = "luci.test"
local ubus_objects = { }
ubus_objects[name] = {
         dump = {
                 function(req, msg)
                         local result = {}
                         local string = "This is a test"
                         local on = true
                         local off = false
                         local positiv = 50000
                         local negativ = -55

                         result["string"] = string
                         result["on"] = on
                         result["off"] = off
                         result["positiv"] = positiv
                         result["negativ"] = negativ

                         conn:reply(req, result);
                 end, {}

conn:add( ubus_objects )
print("Objects added, starting loop")

Incorrect output (lua /root/test.lua):
negativ 1.844674407371e+19
string  This is a test
positiv 50000
on      true
off     false


Correct output if I revert the commit (lua /root/test.lua):
negativ -55
string  This is a test
positiv 50000
on      true
off     false

I think the conversion is wrong here.
I think it must be checked beforehand whether it is a negative number, 
otherwise the typecast is wrong here if this is not taken into account.

Can someone please confirm this!

Best Regards



More information about the openwrt-devel mailing list