X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Fdbus-send.c;h=2e37b08982166b442d46671319805946efdcc793;hb=bdf141e63559dd5c9a1a0ba345e529327aac13e1;hp=c7d509083e3d637045ac9d3edc91ef299e28b77a;hpb=87d324c3434b03214d82c6fc30cb7a6a754318ab;p=platform%2Fupstream%2Fdbus.git diff --git a/tools/dbus-send.c b/tools/dbus-send.c index c7d5090..2e37b08 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -51,7 +51,7 @@ static const char *appname; static void usage (int ecode) { - fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply=(literal)] [--reply-timeout=MSEC] [contents ...]\n", appname); + fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [contents ...]\n", appname); exit (ecode); } @@ -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")) @@ -302,10 +320,8 @@ main (int argc, char *argv[]) usage (1); else if (path == NULL) path = arg; - else if (name == NULL) + else /* name == NULL guaranteed by the 'while' loop */ name = arg; - else - usage (1); } if (name == NULL) @@ -332,6 +348,12 @@ main (int argc, char *argv[]) dbus_error_init (&error); + if (dest && !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);