[PATCH] dbus: fix use of `va_arg` with incorrect type

Artem Sinkevich <[email protected]> Fri, 27 Dec 2024 22:55:30 +0400
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
`rule_len` is computed by iterating over `enum l_dbus_match_type`
(32-bit wide) variadic arguments, but the function also takes
`const char *` (usually 64-bit wide) arguments. Count the arguments
in the same way as they are used below to fix undefined behavior.
---
 ell/dbus.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ell/dbus.c b/ell/dbus.c
index 1ab4ded..7fa5c18 100644
--- a/ell/dbus.c
+++ b/ell/dbus.c
@@ -1825,8 +1825,14 @@ LIB_EXPORT unsigned int l_dbus_add_signal_watch(struct l_dbus *dbus,
 	va_start(args, member);
 
 	rule_len = 0;
-	while (va_arg(args, enum l_dbus_match_type) != L_DBUS_MATCH_NONE)
+	while (true) {
+		type = va_arg(args, enum l_dbus_match_type);
+		if (type == L_DBUS_MATCH_NONE)
+			break;
+
+		va_arg(args, const char *);
 		rule_len++;
+	}
 
 	va_end(args);
 
-- 
2.47.1