From 17876a2ba99daa8d613bd2cf6f8523d33ec7052b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 5 Apr 2011 18:38:58 +0100 Subject: [PATCH] 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 --- dbus/Makefile.am | 2 +- dbus/dbus-gidl.c | 11 +++++++++++ dbus/dbus-gparser.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 5f438b8..48ccce1 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -75,7 +75,7 @@ libdbus_gtool_la_SOURCES = $(DBUS_GLIB_INTERNALS) \ dbus-gparser.c \ dbus-gparser.h -libdbus_gtool_la_LIBADD = $(DBUS_LIBS) -lexpat +libdbus_gtool_la_LIBADD = $(DBUS_LIBS) $(DBUS_GLIB_LIBS) -lexpat bin_PROGRAMS=dbus-binding-tool diff --git a/dbus/dbus-gidl.c b/dbus/dbus-gidl.c index 6d93467..f9efefb 100644 --- a/dbus/dbus-gidl.c +++ b/dbus/dbus-gidl.c @@ -24,6 +24,8 @@ #include "dbus-gidl.h" +#include + #ifndef DOXYGEN_SHOULD_SKIP_THIS struct BaseInfo @@ -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 87e156d..91e155d 100644 --- a/dbus/dbus-gparser.c +++ b/dbus/dbus-gparser.c @@ -27,6 +27,8 @@ #include "dbus/dbus-signature.h" #include +#include + #include #define _(x) gettext ((x)) #define N_(x) x @@ -358,6 +360,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); @@ -410,6 +420,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); @@ -460,6 +478,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); @@ -568,7 +594,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); -- 1.7.4.1