Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by bhuna.collabora.co.uk (Postfix) with ESMTP id 601EA1A8804E for ; Fri, 31 May 2013 09:24:10 +0100 (BST) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B400EE619F for ; Fri, 31 May 2013 01:24:09 -0700 (PDT) X-Original-To: dbus@lists.freedesktop.org Delivered-To: dbus@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A768E5C63 for ; Fri, 31 May 2013 01:23:55 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 31 May 2013 01:24:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.87,777,1363158000"; d="scan'208";a="346077828" Received: from chengwei-ubuntu.bj.intel.com ([10.238.155.181]) by fmsmga002.fm.intel.com with ESMTP; 31 May 2013 01:23:53 -0700 From: Chengwei Yang To: dbus@lists.freedesktop.org Subject: [PATCH] dbus-send: check usage a bit strictly Date: Fri, 31 May 2013 16:23:51 +0800 Message-Id: <1369988631-7615-1-git-send-email-chengwei.yang@intel.com> X-Mailer: git-send-email 1.7.9.5 X-BeenThere: dbus@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: dbus-bounces+simon.mcvittie=collabora.co.uk@lists.freedesktop.org Errors-To: dbus-bounces+simon.mcvittie=collabora.co.uk@lists.freedesktop.org X-DSPAM-Result: Innocent X-DSPAM-Processed: Fri May 31 09:24:19 2013 X-DSPAM-Confidence: 0.9996 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 5,51a85e3319126377470953 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 --- 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 _______________________________________________ dbus mailing list dbus@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dbus