From ee0f90d5d619ef53f30edbbeb19c7b6a5055a84b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 14 Jan 2014 11:22:34 +0000 Subject: dbus-binding-tool: check for valid interface, member and property names Properties are currently allowed to be arbitrary UTF-8 since this matches dbus-glib's runtime behaviour, although ideally new interfaces should use the more restrictive member naming rules (leading to names like MyProperty) for interop with QtDBus. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=7909 Reviewed-by: Cosimo Alfarano --- diff --git a/dbus/dbus-gidl.c b/dbus/dbus-gidl.c index b5293bd..cde4d79 100644 --- a/dbus/dbus-gidl.c +++ b/dbus/dbus-gidl.c @@ -26,6 +26,8 @@ #include "dbus-gidl.h" +#include + struct BaseInfo { unsigned int refcount : 28; @@ -342,6 +344,8 @@ interface_info_new (const char *name) { InterfaceInfo *info; + g_return_val_if_fail (g_dbus_is_interface_name (name), NULL); + info = g_new0 (InterfaceInfo, 1); info->base.refcount = 1; info->base.name = g_strdup (name); @@ -467,6 +471,8 @@ method_info_new (const char *name) { MethodInfo *info; + g_return_val_if_fail (g_dbus_is_member_name (name), NULL); + info = g_new0 (MethodInfo, 1); info->base.refcount = 1; info->base.name = g_strdup (name); @@ -573,6 +579,8 @@ signal_info_new (const char *name) { SignalInfo *info; + g_return_val_if_fail (g_dbus_is_member_name (name), NULL); + info = g_new0 (SignalInfo, 1); info->base.refcount = 1; info->base.name = g_strdup (name); @@ -637,6 +645,9 @@ property_info_new (const char *name, { PropertyInfo *info; + g_return_val_if_fail (g_utf8_validate (name, -1, NULL), NULL); + g_return_val_if_fail (g_variant_is_signature (type), NULL); + info = g_new0 (PropertyInfo, 1); info->base.refcount = 1; info->base.name = g_strdup (name); diff --git a/dbus/dbus-gparser.c b/dbus/dbus-gparser.c index 2e0668e..af74e30 100644 --- a/dbus/dbus-gparser.c +++ b/dbus/dbus-gparser.c @@ -30,6 +30,8 @@ #include "dbus/dbus-signature.h" #include +#include + #define ELEMENT_IS(name) (strcmp (element_name, (name)) == 0) typedef struct @@ -352,6 +354,14 @@ parse_interface (Parser *parser, return FALSE; } + if (!g_dbus_is_interface_name (name)) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_PARSE, + "\"%s\" is not a valid D-Bus interface name", name); + return FALSE; + } + top = parser->node_stack->data; iface = interface_info_new (name); @@ -404,6 +414,14 @@ parse_method (Parser *parser, return FALSE; } + if (!g_dbus_is_member_name (name)) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_PARSE, + "\"%s\" is not a valid D-Bus member name", name); + return FALSE; + } + method = method_info_new (name); interface_info_add_method (parser->interface, method); method_info_unref (method); @@ -454,6 +472,14 @@ parse_signal (Parser *parser, return FALSE; } + if (!g_dbus_is_member_name (name)) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_PARSE, + "\"%s\" is not a valid D-Bus member name", name); + return FALSE; + } + signal = signal_info_new (name); interface_info_add_signal (parser->interface, signal); signal_info_unref (signal); @@ -562,7 +588,15 @@ parse_property (Parser *parser, access, element_name); return FALSE; } - + + if (!g_utf8_validate (name, -1, NULL)) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_PARSE, + "\"%s\" is not UTF-8", name); + return FALSE; + } + property = property_info_new (name, type, access_flags); interface_info_add_property (parser->interface, property); property_info_unref (property); -- cgit v0.9.0.2-2-gbebe