sys: use strstr() to detect installed packages
authorDaniel Golle <daniel@makrotopia.org>
Wed, 23 Oct 2024 20:06:18 +0000 (21:06 +0100)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 23 Aug 2025 14:11:27 +0000 (16:11 +0200)
Don't rely on sscanf() doesn't care about unused suffixes of the status
string. Use strstr() instead to make sure only actually installed
packages are returned.

Suggested-by: Eric Fahlgren <ericfahlgren@gmail.com>
Reported-by: Eric Fahlgren <ericfahlgren@gmail.com>
Fixes: #6
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Link: https://github.com/openwrt/rpcd/pull/8
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
sys.c

diff --git a/sys.c b/sys.c
index da3508ea989cfae34deb10d612c8707535281cd6..a41095ad2e46162902ade77d747ef36576c5e93f 100644 (file)
--- a/sys.c
+++ b/sys.c
@@ -233,8 +233,7 @@ rpc_sys_packagelist(struct ubus_context *ctx, struct ubus_object *obj,
                        break;
                case 'S':
                        if (is_field("Status", line))
-                               if (sscanf(line, "Status: install %63s installed", tmp) == 1)
-                                       installed = true;
+                               installed = !!strstr(line, " installed");
                        break;
                default:
                        if (is_blank(line)) {