Skip to contentSkip to conversation

dbus: fix use of `va_arg` with incorrect type

PATCH Applied Artem Sinkevich 2 participants 2 messages Dec 27, 2024 – Jan 5, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dbus: fix use of `va_arg` with incorrect type

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(-)
ell/dbus.c +7 -1
index 1ab4ded..7fa5c18 100644
@@ -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);
 
Signature · 1 line
2.47.1
#1 lore raw

Hi Artem,

Quoted 8 lines · Artem Sinkevich

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(-)

Applied, thanks!

Regards,
-Denis