From dbd459ec9253fe97441e7c54b136c929074c4762 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Aug 2021 18:07:50 +0200 Subject: [PATCH] nm-sudo: expect unknown interface in _bus_method_call() GDBus will invoke the method_call callback also for the Get/Set functions. Thus, we need to check the interface_name and handle them (actually, there is nothing to handle, no properties exist). Also, "Ping" method only exists for testing. It is usually not called in production, so check for "GetFD" first. --- src/nm-sudo/nm-sudo.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/nm-sudo/nm-sudo.c b/src/nm-sudo/nm-sudo.c index c199d8994b..d8cf42f3c8 100644 --- a/src/nm-sudo/nm-sudo.c +++ b/src/nm-sudo/nm-sudo.c @@ -290,14 +290,26 @@ _bus_method_call(GDBusConnection * connection, method_name, g_variant_get_type_string(parameters)); + if (!nm_streq(interface_name, NM_SUDO_DBUS_IFACE_NAME)) + goto out_unknown_method; + + if (nm_streq(method_name, "GetFD")) { + g_variant_get(parameters, "(u)", &arg_u); + _handle_get_fd(gl, invocation, arg_u); + return; + } if (nm_streq(method_name, "Ping")) { g_variant_get(parameters, "(&s)", &arg_s); _handle_ping(gl, invocation, arg_s); - } else if (nm_streq(method_name, "GetFD")) { - g_variant_get(parameters, "(u)", &arg_u); - _handle_get_fd(gl, invocation, arg_u); - } else - nm_assert_not_reached(); + return; + } + +out_unknown_method: + g_dbus_method_invocation_return_error(invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_UNKNOWN_METHOD, + "Unknown method %s", + method_name); } static GDBusInterfaceInfo *const interface_info = NM_DEFINE_GDBUS_INTERFACE_INFO(