From patchwork Thu Aug 31 10:36:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 808162 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::23c; helo=mail-lf0-x23c.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbfgot7gqkgqel27xxdy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="pW52qwbK"; dkim-atps=neutral Received: from mail-lf0-x23c.google.com (mail-lf0-x23c.google.com [IPv6:2a00:1450:4010:c07::23c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xjf3Y5CFyz9s2G for ; Thu, 31 Aug 2017 20:38:15 +1000 (AEST) Received: by mail-lf0-x23c.google.com with SMTP id a126sf128329lfa.15 for ; Thu, 31 Aug 2017 03:38:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1504175893; cv=pass; d=google.com; s=arc-20160816; b=0nUmq/JjR9AVGnB9fi8eLH+NdbkPy5Ii156nY9ze6xnKFVnPRswLOZJ2ZQHn/y2lU7 +vQ1u+pYatIzOkfiArc8QMw2Q6lkH9UNwjDDMCwxKPDrNx9JYMaAEJm5e1m7TX/Kyh0U dU2fEmDDweux/Vx6QnxCPbVNjqn/zUMvJ0/LtwyHkYakkbbIG9ojtUsP6zlIUu5Ru7Cm KYuMdPZCp8CJdxKdubg8iFs9VyysCP0gmdAKkC2U5G/HcRWujZiJFZt2CBCf43DHuFvC vVjMj7Odwmryxw7ExcBhr1x4AiC5EoR3HRDoPntgt8Lbi+r/NvfEhTOJ6Ru7P4xCe3yh frjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=5Egx635ScbSGUt4UqB1NtOVrtmBDH2WN7s1nVoCodvc=; b=RCLCd/6AuuQmloDY4yiFWj7n+mlBmWUQ6QEXm3Gm5gv7v32xTxgo38diHprorE5q/Z wbI5rzLi41COeMbEAxbZFd/bARXoQbA/g9Zoa4zEtc8aG+F4Qnv5HZopkNNUV+igAIC7 8jxsVfetFyj23uCsUgZmwUnJOS3ydMgpgzSGGRq4CKU7mK3Vhzt2nx1PBEH8jEdVk4lh As2T3sXekRJ7cTGPAiVWFjJM5SNS/kEeK73rX27RezpgWTw7l3suNHB/4WxmHeI3Gkl4 Xr5TSx3ontrV4lJji+C+1JEXVXTvZgT9kxPvz0e6H++/LsIQoYTrC5w+w7fII7M7R1mo HUsw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.2 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=5Egx635ScbSGUt4UqB1NtOVrtmBDH2WN7s1nVoCodvc=; b=pW52qwbKdnDixEUtxfKIkNO+8QFTmYgBzXUTmqgc+T6ZQGxo0V0UmhwBenTbOMv651 pdDyGOfPnomkiPokxRfosyxUzmGd8fktsVl5BWAj+kzovOqPHo8aliqBZ31xmmZbtTfC UWeDDRQPgDbLDFaOHOrKInHJxNO9ewrK/0/qT3pxAFmF0gF+yCZKVbl7/Uyy2X9o4LrB 2wNUKuFfqFKdzN3kYKvXbhZ0aCIEzocjPtD2gyIK16dAXOMRQrRy8RBbytYzykosHDWQ VuKtWh6RVyx2yDK+RMgPiKOOYDwgGX0kB2/tqf9DoCBG9YXTvlx0W/WFz5CNvZZm8eDj UzbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=5Egx635ScbSGUt4UqB1NtOVrtmBDH2WN7s1nVoCodvc=; b=jPjrhiHbHyqhKfEPi2m/hemCTfxCcGTEz9wc+X8UbZ29M+V6dM6aj83iw7YGOA40mV Sa9DnZSs7vC1lDZvKafSiEf/Ky5ztwVW8Lp697yHiQRgY+WmRY9DANXGtoark0+MpHMT q4USzcH5fcqsdIl3AcxeKtXAYrP0aqCdS2Xx2Oq9Wu5g8mGwL2tdyDcQTNuDdMhKw3hL CZ9yODVpG2ZCDCJ9hADCwwnDY2mkIM1PCgaKvpZDdZVb3Sr1OQQt2qYngnf+pIZIKYOM ep9u9CWs4DarixG5gK2C+aT2Niii3f+Ms+Ett1jrPrP/qcJNKoof2F1auiYPYzGoYAR5 sk2g== Sender: swupdate@googlegroups.com X-Gm-Message-State: AHPjjUiiY7P27tk9L9GPEd2qBjAWSxV0l6KamdPdYrPtg3zuIb1xl1Km jFpsSdQzzDKFiw== X-Received: by 10.25.196.70 with SMTP id u67mr8131lff.14.1504175893203; Thu, 31 Aug 2017 03:38:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.80.71 with SMTP id v7ls587598ljd.13.gmail; Thu, 31 Aug 2017 03:38:12 -0700 (PDT) X-Received: by 10.46.19.10 with SMTP id 10mr414721ljt.35.1504175892706; Thu, 31 Aug 2017 03:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504175892; cv=none; d=google.com; s=arc-20160816; b=jY9HnVkG+KdVITnn2U/kt32prHhT8uEbhmo/EhxuxA6NhGPCQOvs9yRHn0M5dl58hb cAkXIHKup/f2ZNA5wCRVhZI6O5RU5qyuqIg2WnuTskDUIZKOLR1nL3+npj3tasxnDZUn QbfOv9DpDTu6/niJZCZccYcBiTQF4gGd4+6y6STT2Dj+U8dCTIDCQYrdxaIdLodL6ETd yLgy6K0dlEgp5h/2qLFVm8Symx2n/emGtQKZWbSRx6myJoRlM8KSYTSdYVPtIG47gTDH x5iWrBk68HrW7eXCMB8PdGywkpKhafhkG24Lg+wbgIJ5cxTTuKq/m5r8YQm8DQ+9BMHy mTbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AD1IB6blnuekrd7enK8p9v7zMj+jc+lTT4SmECwJc10=; b=kmE2CwQzoGm93KK3JnjGMz9wysfJF7jWhsw1ORSgJe/qNhBGDsFRQnbpdBJ0ms+6HY 1jAwPCUTKP0Ov3bUd5uefCKmB0/msTuoRq7ddbSW3TtOdT6l9R0F9WWamPcq8y2ZAyTX Qd/A30sSJzaj6pdMf5R5o2t/mwXi/DirEAdIpTAEAozRONLXAI68MF10YzUapNND7tyh cfeFQKd9CoMxroJ/TOj7LnL5DNcv15CQuyjrFX361baBwhUXk4RZxVrjjzCsj1jneeRW 4cPOOWgxHiw91b1fmo+cs7mtGLkCOwYVLJY1Nre7aJd7fOe5yEk+8XikG31cZjFzpJfP +NUA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.2 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id 75si5271wma.7.2017.08.31.03.38.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Aug 2017 03:38:12 -0700 (PDT) Received-SPF: neutral (google.com: 192.35.17.2 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) client-ip=192.35.17.2; Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id v7VAcC4a032407 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 31 Aug 2017 12:38:12 +0200 Received: from MD1KR9XC.ad001.siemens.net ([139.25.69.251]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id v7VAcCbx025099; Thu, 31 Aug 2017 12:38:12 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH v2] core: make cmdline parsing more robust Date: Thu, 31 Aug 2017 12:36:01 +0200 Message-Id: <20170831103601.13500-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <2a9c51d7-a92a-09b9-27a2-89bee07c5f17@denx.de> References: <2a9c51d7-a92a-09b9-27a2-89bee07c5f17@denx.de> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 192.35.17.2 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , (1) disallow options' values starting with '-' except for downloader, webserver, and suricatta doing their own cmdline parsing. Otherwise, e.g., this command $ swupdate -l -c -i installs instead of checking it due to -l's option value missing. (2) abort on superfluous non-option cmdline arguments as SWUpdate doesn't use them, probably an usage error. (3) check some sensible combinations with suricatta mode Signed-off-by: Christian Storm --- core/swupdate.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/swupdate.c b/core/swupdate.c index b01aadd..1f0ba0d 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -599,6 +599,13 @@ int main(int argc, char **argv) /* Process options with getopt */ while ((c = getopt_long(argc, argv, main_options, long_options, NULL)) != EOF) { + if (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w')) { + /* An option's value starting with '-' is not allowed except + * for downloader, webserver, and suricatta doing their own + * argv parsing. + */ + c = '?'; + } switch (c) { case 'v': loglevel = TRACELEVEL; @@ -680,6 +687,12 @@ int main(int argc, char **argv) } } + if (optind < argc) { + /* SWUpdate has no non-option arguments, fail on them */ + usage(argv[0]); + exit(1); + } + /* * Parameters are parsed: now performs plausibility * tests before starting processes and threads @@ -698,6 +711,13 @@ int main(int argc, char **argv) exit(1); } +#ifdef CONFIG_SURICATTA + if (opt_u && (opt_c || opt_i)) { + fprintf(stderr, "invalid mode combination with suricatta.\n"); + exit(1); + } +#endif + swupdate_crypto_init(); if (strlen(swcfg.globals.publickeyfname)) {