From 4434ea41e9a15c1068d48bd0f6e168d488a5d3dc Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 2 Jun 2017 19:32:24 +0100 Subject: [PATCH] bus/containers: Do some basic checking on the parameters In particular, we now fail early if we can't extract the file descriptor, or if there are named parameters (none are supported yet). Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354 --- bus/containers.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/bus/containers.c b/bus/containers.c index e8935490..cf9156f4 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -29,13 +29,86 @@ # error DBUS_ENABLE_CONTAINERS requires DBUS_UNIX #endif +#include "dbus/dbus-internals.h" +#include "dbus/dbus-sysdeps-unix.h" + dbus_bool_t bus_containers_handle_add_server (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, DBusError *error) { + DBusMessageIter iter; + DBusMessageIter dict_iter; + const char *type; + const char *name; + + /* We already checked this in bus_driver_handle_message() */ + _dbus_assert (dbus_message_has_signature (message, "ssa{sv}a{sv}")); + + /* Argument 0: Container type */ + if (!dbus_message_iter_init (message, &iter)) + _dbus_assert_not_reached ("Message type was already checked"); + + _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); + dbus_message_iter_get_basic (&iter, &type); + + if (!dbus_validate_interface (type, NULL)) + { + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "The container type identifier must have the " + "syntax of an interface name"); + goto fail; + } + + /* Argument 1: Name as defined by container manager */ + if (!dbus_message_iter_next (&iter)) + _dbus_assert_not_reached ("Message type was already checked"); + + _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); + dbus_message_iter_get_basic (&iter, &name); + + /* Argument 2: Metadata as defined by container manager */ + if (!dbus_message_iter_next (&iter)) + _dbus_assert_not_reached ("Message type was already checked"); + + _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY); + /* TODO: Copy the metadata */ + + /* Argument 3: Named parameters */ + if (!dbus_message_iter_next (&iter)) + _dbus_assert_not_reached ("Message type was already checked"); + + _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY); + dbus_message_iter_recurse (&iter, &dict_iter); + + while (dbus_message_iter_get_arg_type (&dict_iter) != DBUS_TYPE_INVALID) + { + DBusMessageIter pair_iter; + const char *param_name; + + _dbus_assert (dbus_message_iter_get_arg_type (&dict_iter) == + DBUS_TYPE_DICT_ENTRY); + + dbus_message_iter_recurse (&dict_iter, &pair_iter); + _dbus_assert (dbus_message_iter_get_arg_type (&pair_iter) == + DBUS_TYPE_STRING); + dbus_message_iter_get_basic (&pair_iter, ¶m_name); + + /* If we supported any named parameters, we'd copy them into a data + * structure here; but we don't, so fail instead. */ + dbus_set_error (error, DBUS_ERROR_INVALID_ARGS, + "Named parameter %s is not understood", param_name); + goto fail; + } + + /* End of arguments */ + _dbus_assert (!dbus_message_iter_has_next (&iter)); + + /* TODO: Actually implement the method */ dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + +fail: return FALSE; } -- 2.13.3