From d952d1db1866aac8b2cec32f9c771c362f7e73c6 Mon Sep 17 00:00:00 2001 From: Yuen Su Date: Mon, 19 Oct 2026 22:19:51 +0800 Subject: [PATCH] mwan3: fix empty rpcd integer state in 2.12.3 An empty mwan3track state file becomes NaN in the rpcd response. Default failed integer conversions to zero, as the shell handler did. Add a focused regression for the installed integer helpers in a separate ucode file called from test.sh, and bump the package version. Fixes: #29653 Signed-off-by: Yuen Su --- net/mwan3/Makefile | 4 ++-- net/mwan3/files/usr/share/rpcd/ucode/mwan3 | 2 +- net/mwan3/test-rpcd.uc | 17 +++++++++++++++++ net/mwan3/test.sh | 4 ++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 net/mwan3/test-rpcd.uc diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 48c3aebc165b6..7eee43dcbf3e5 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,8 +8,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.12.2 -PKG_RELEASE:=2 +PKG_VERSION:=2.12.3 +PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPL-2.0 diff --git a/net/mwan3/files/usr/share/rpcd/ucode/mwan3 b/net/mwan3/files/usr/share/rpcd/ucode/mwan3 index 2e145c72e5c24..913aae32582da 100644 --- a/net/mwan3/files/usr/share/rpcd/ucode/mwan3 +++ b/net/mwan3/files/usr/share/rpcd/ucode/mwan3 @@ -14,7 +14,7 @@ function get_str(iface, property) { } function get_int(iface, property) { - return int(get_str(iface, property)); + return int(get_str(iface, property)) || 0; } function get_uptime() { diff --git a/net/mwan3/test-rpcd.uc b/net/mwan3/test-rpcd.uc new file mode 100644 index 0000000000000..ec85758c512bf --- /dev/null +++ b/net/mwan3/test-rpcd.uc @@ -0,0 +1,17 @@ +import { readfile } from 'fs'; + +const source = readfile('/usr/share/rpcd/ucode/mwan3'); +const begin = index(source, 'function get_str_raw('); +const end = index(source, 'function get_uptime('); +if (begin < 0 || end <= begin) + die('Cannot find mwan3 integer helpers\n'); +const read_integer = loadstring(substr(source, begin, end - begin) + + '\nreturn get_int("wan", "SCORE");', { raw_mode: true }); + +for (let sample in [['', 0], [null, 0], ['\n', 0], ['invalid', 0], + ['0', 0], ['17', 17], ['17\n', 17]]) { + const actual = call(read_integer, null, { readfile: () => sample[0] }); + if (actual !== sample[1]) + die(sprintf('get_int(%J): expected %d, got %J\n', sample[0], sample[1], actual)); + printf('get_int(%J): %d\n', sample[0], actual); +} diff --git a/net/mwan3/test.sh b/net/mwan3/test.sh index c3982c6d33f6b..49c036ec681fb 100755 --- a/net/mwan3/test.sh +++ b/net/mwan3/test.sh @@ -37,3 +37,7 @@ actual=$(sanitize_route "$ipv6_route") echo "actual: '$actual'" >&2 exit 1 } + +# Check that empty, missing and invalid rpcd state becomes zero. +# Numeric values must be preserved. +ucode -S "$(dirname "$0")/test-rpcd.uc"