From patchwork Thu Aug 17 14:29:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 802709 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:400c:c0c::23e; helo=mail-wr0-x23e.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbqwr23gakgqejdadcfa@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Tn3DFOLH"; dkim-atps=neutral Received: from mail-wr0-x23e.google.com (mail-wr0-x23e.google.com [IPv6:2a00:1450:400c:c0c::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xY7v975NBz9t4P for ; Fri, 18 Aug 2017 00:31:33 +1000 (AEST) Received: by mail-wr0-x23e.google.com with SMTP id f8sf28174wrf.3 for ; Thu, 17 Aug 2017 07:31:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1502980291; cv=pass; d=google.com; s=arc-20160816; b=uhItFylHUaiITy/rkGKc2b2KKHjxWTw1UaPAlqs3WCOY3Hl1rqBrlGIiBKKXfBlM3T cTySQ8TTPb0o82i8aGehSxqc0VyA7Ungdjisd8TeC0yuULtsuRIjC05SrXrPVU9oUdy6 psklJEiy7xuT5lpffYvWon7VKBQrEmDH3mf+tSV0I34j6E7A24J8gFEEyhHXzgHGpYvt 4L1pRS1OOoUfaFSBHgIwX5mT3oJtPZxFDdZUEoyMlwoZT/mLw8rGUbpz/1CHnMgRMoYD kfDFBkmqjVhTxqmo7+ze2xwNVk58dGYO31x9q6HkvOYbnZ38CC8V5qvMbUEOJzihCgPI 8SuA== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=cxmyUoT6zzJ8tprPI/viSdq1bTqSssvYCdZx0ge/Li0=; b=vPgGOjM+2lR90tNaUxxdQGOok0lAAdYknP1Z2V+jK1JcCU/T1NsAfXRntJCp7dMvFa j2H20zOEuQGe5DfTWNYhCg0Buw2f3G7UIbOdwHS24kcJX3g7gSMJJpqlL/tM/JVLzwqk /3rN1yxMHATSE04B58tU0E4si2qLKWrCP9DCZGjib1GIbRZz/4RuKOuEZrdmskIhLNOK abVOgccHweRKfoTaQX5VEV8fj7rctRfEOFm/O5HQnmWWdGptrxc4+DrfbQLeVHUIu6Oh sLAHyDZSFGz22LGdPLg049EapKMcn0zJW1/f0aL+lkkyI+mDPb5wZfBTVbSmrlYRrhQ7 OJnA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.28 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 :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=cxmyUoT6zzJ8tprPI/viSdq1bTqSssvYCdZx0ge/Li0=; b=Tn3DFOLHA5lUw+WnDcbNogKOIXuKLWcP5pkhrzS5drA7LoGLLEtE2HNsbvfsgrfurV Jqtu4HT4idlxTUatVNOVHLRckloVC5qjTbrj2GOX8/co7UZcwy5Gj/TO9pau99Jl4Y28 6BdiamPOhXbLLbqhoEV7oeiv9kSQ19pLWmcwwNmXBed1P+q+0hpEDdcxrOzOO7/XXu1J ALIkhLelJzf05uj9vHny6YBa4qD0QkWL12lZgnUr+rAwjvQ3WGTWtrB4hdNr0xTxtIUO vGhAQJrhK5htA7+yevtSNqKqi61ITBPUs8FzVZCdBSXiSXh/zYWIAvfuDsofZ+OyIfIA sk2g== 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: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=cxmyUoT6zzJ8tprPI/viSdq1bTqSssvYCdZx0ge/Li0=; b=hPqiz7fNdLtPBTfv3A9JyRGo17NfSGl3UCO/OZJgsT/8aKSd0nATlNE3w1HWzOS+9D MscHWRmv9SzlSMbzWGPFTc6KzP49r1NIIPuOWpUsUqUv6uCfdC6IbSbs1jdFP1hoYgSN Mvl4M79Yz5EFNQqmAux0VETPXZkS2lRbFOFMMb8amJZZRiQIKLYX+NNtBpDpEggfPgwd rKIFYMNIQsZmlDNzzkIFj2EdG6lHurYbm8j0VT9pLqgNM8dsTGR79SroWp7i+GeJ761B WndrR50nKyfO3R6P47y7aUMsCKCsPas3uyRpt7BmuBGq7MpDVEzEmdoTkWPPIgzzP92r 8w/w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AHYfb5jHbo24cd6tCN4O+o5TXiha6JuNJxp16zECV/rPMw/UEjusdTul ggPMPIXS9FNnmA== X-Received: by 10.46.32.135 with SMTP id g7mr10743lji.18.1502980290947; Thu, 17 Aug 2017 07:31:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.25.196.4 with SMTP id u4ls226008lff.30.gmail; Thu, 17 Aug 2017 07:31:30 -0700 (PDT) X-Received: by 10.25.18.205 with SMTP id 74mr48667lfs.35.1502980290372; Thu, 17 Aug 2017 07:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502980290; cv=none; d=google.com; s=arc-20160816; b=ggneoXvtUKrZALILz/wEYCsSprmlBBQ8vQpJbK8UAzXNQzmDdusZ5CzJXDDaIcZLCG Bm8kIFPU1VSDrRExB47UEv90dE4b9tYgIjQKm2jJzXXiAXm3edFOLiDdrS+J0TsGYNj4 K57eU2RUaWPTKVXnN4eZ8MEy3hKjEKAO/I2CCPE7SSs/1/BlC6Xt56C/7zpOc+zuHZ/c t1SJO48gMAIudO2SyJaGJaGJNvw4pz/vto1NFvGcU/6ePF12rOMHpg9MTljU2AyC6Njx Enwx/92DBHogyHWdqi59+SPPTKiyt2+4suqwGGn/JrDefy0q8THEY5Uq8Uj39PiNFNrW T3xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=O2d/R7akPed5PYzZyfj3nGqCqfnL+LWCA797S3vqS2U=; b=j+VBtPub3rpZ7m5G3r2Oyr3IsWjWrOBFp1HLEFc5fB/KBqewEHyWN4yWlT+04qOSop 6zGvLGePBr3nhn9+78Ut8KuEAelAYnk20HWV8TK6V6esaO7aWf94qE12rhCGoKadFxPn 10jlUSiwNwzIfDqOODrNs+/GSSrEPbAwotAwW8KeQzs2A9e608bLAyghnFfK+Mr5aq1C eJJoSJrEPoAzvg8ZKj0iewQcI9t93bthr57kpp/o+KmEoRxhwJmYhMg6S50L17uk/3S9 lSPaYZHkDT+oXhoRMuIYY/t3ouHpUFvvmyvTc/WNwsKp3MHyQPeS2eZ7WdoV8BSu9EWN K0RQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 192.35.17.28 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) smtp.mailfrom=christian.storm@siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id b125si1627938wmc.1.2017.08.17.07.31.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Aug 2017 07:31:30 -0700 (PDT) Received-SPF: neutral (google.com: 192.35.17.28 is neither permitted nor denied by best guess record for domain of christian.storm@siemens.com) client-ip=192.35.17.28; Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id v7HEVUcc027534 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 17 Aug 2017 16:31:30 +0200 Received: from MD1KR9XC.ww002.siemens.net ([139.25.68.253]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id v7HEVTF5024365; Thu, 17 Aug 2017 16:31:29 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH resent] core: make cmdline parsing more robust Date: Thu, 17 Aug 2017 16:29:42 +0200 Message-Id: <20170817142942.4328-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.14.1 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 192.35.17.28 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 sensible combinations with suricatta mode Signed-off-by: Christian Storm --- core/swupdate.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/swupdate.c b/core/swupdate.c index b01aadd..f364bce 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -599,6 +599,12 @@ 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 +686,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 +710,18 @@ int main(int argc, char **argv) exit(1); } +#ifdef CONFIG_SURICATTA + if (opt_u && (opt_c || opt_i +#ifdef CONFIG_DOWNLOAD + || opt_d +#endif + )) { + fprintf(stderr, "invalid mode combination with suricatta.\n"); + usage(argv[0]); + exit(1); + } +#endif + swupdate_crypto_init(); if (strlen(swcfg.globals.publickeyfname)) {