[PATCH] dbus-send: check usage a bit strictly

Chengwei Yang chengwei.yang at intel.com
Fri May 31 01:23:51 PDT 2013


1. align --print-reply=, --reply-timeout=, --dest= with --address=.

2. check --print-reply more strictly as the usage says, only =literal is
a valid optional value.

Signed-off-by: Chengwei Yang <chengwei.yang at intel.com>
---
 tools/dbus-send.c |   41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/tools/dbus-send.c b/tools/dbus-send.c
index e403a58..5906164 100644
--- a/tools/dbus-send.c
+++ b/tools/dbus-send.c
@@ -266,36 +266,55 @@ 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);
 	}
       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;
+	{
+	  if (*(strchr (arg, '=') + 1) == '\0')
+	    {
+	      fprintf (stderr, "\"--type=\" requires an TYPE\n");
+	      usage (1);
+	    }
+	  type_str = strchr (arg, '=') + 1;
+	}
       else if (!strcmp(arg, "--help"))
 	usage (0);
       else if (arg[0] == '-')
-- 
1.7.9.5



More information about the dbus mailing list