summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChengwei Yang <chengwei.yang@intel.com>2013-06-06 16:58:11 +0800
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-06-06 13:07:51 +0100
commitc690ee4351f99ed5e629ffcf5f4a2edcd418d103 (patch)
tree5ed0c8316e5c747e5f800643dbb9155e237ec2af /tools
parentc9b942e56f5b0a166cfc7ab4f53c54449a9db8de (diff)
downloaddbus-c690ee4351f99ed5e629ffcf5f4a2edcd418d103.tar.gz
dbus-send: check usage a bit strictly
This commit does several more strictly check for dbus-send as its usage suggested. * now --address is an invalid option but --address=, this just like the others, say --reply-timeout=, --dest=, --type= * --print-reply= only take an optional argument "=literal" * --print-reply= will cause error with missing MSEC and invalid MSEC will cause invalid value error * --dest= will cause error with missing a NAME and also call dbus_validate_bus_name to verify the NAME Signed-off-by: Chengwei Yang <chengwei.yang@intel.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65424 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Diffstat (limited to 'tools')
-rw-r--r--tools/dbus-send.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/tools/dbus-send.c b/tools/dbus-send.c
index e403a587..ca5dd5c6 100644
--- a/tools/dbus-send.c
+++ b/tools/dbus-send.c
@@ -266,34 +266,52 @@ main (int argc, char *argv[])
type = DBUS_BUS_SESSION;
session_or_system = TRUE;
}
- else if (strstr (arg, "--address") == arg)
+ else if (strstr (arg, "--address=") == arg)
{
- address = strchr (arg, '=');
-
- if (address == NULL)
+ if (*(strchr (arg, '=') + 1) == '\0')
{
fprintf (stderr, "\"--address=\" requires an ADDRESS\n");
usage (1);
}
- else
- {
- address = address + 1;
- }
+ address = strchr (arg, '=') + 1;
}
else if (strncmp (arg, "--print-reply", 13) == 0)
{
print_reply = TRUE;
message_type = DBUS_MESSAGE_TYPE_METHOD_CALL;
- if (*(arg + 13) != '\0')
+ if (strcmp (arg + 13, "=literal") == 0)
print_reply_literal = TRUE;
+ else if (*(arg + 13) != '\0')
+ {
+ fprintf (stderr, "invalid value (%s) of \"--print-reply\"\n", arg + 13);
+ usage (1);
+ }
}
else if (strstr (arg, "--reply-timeout=") == arg)
{
+ if (*(strchr (arg, '=') + 1) == '\0')
+ {
+ fprintf (stderr, "\"--reply-timeout=\" requires an MSEC\n");
+ usage (1);
+ }
reply_timeout = strtol (strchr (arg, '=') + 1,
NULL, 10);
+ if (reply_timeout <= 0)
+ {
+ fprintf (stderr, "invalid value (%s) of \"--reply-timeout\"\n",
+ strchr (arg, '=') + 1);
+ usage (1);
+ }
}
else if (strstr (arg, "--dest=") == arg)
- dest = strchr (arg, '=') + 1;
+ {
+ if (*(strchr (arg, '=') + 1) == '\0')
+ {
+ fprintf (stderr, "\"--dest=\" requires an NAME\n");
+ usage (1);
+ }
+ dest = strchr (arg, '=') + 1;
+ }
else if (strstr (arg, "--type=") == arg)
type_str = strchr (arg, '=') + 1;
else if (!strcmp(arg, "--help"))
@@ -330,6 +348,12 @@ main (int argc, char *argv[])
dbus_error_init (&error);
+ if (!dbus_validate_bus_name (dest, &error))
+ {
+ fprintf (stderr, "invalid value (%s) of \"--dest\"\n", dest);
+ usage (1);
+ }
+
if (address != NULL)
{
connection = dbus_connection_open (address, &error);