[{"id":1762517,"web_url":"http://patchwork.ozlabs.org/comment/1762517/","msgid":"<225b739e-6343-9236-1a58-e90ff87aab53@denx.de>","list_archive_url":null,"date":"2017-09-04T08:28:13","subject":"Re: [swupdate] [PATCH v2] core: make cmdline parsing more robust","submitter":{"id":5771,"url":"http://patchwork.ozlabs.org/api/people/5771/","name":"Stefano Babic","email":"sbabic@denx.de"},"content":"On 31/08/2017 12:36, Christian Storm wrote:\n> (1) disallow options' values starting with '-' except for\n>     downloader, webserver, and suricatta doing their own\n>     cmdline parsing. Otherwise, e.g., this command\n>     $ swupdate -l -c -i <file>\n>     installs <file> instead of checking it due to -l's\n>     option value missing.\n> (2) abort on superfluous non-option cmdline arguments\n>     as SWUpdate doesn't use them, probably an usage error.\n> (3) check some sensible combinations with suricatta mode\n> \n> Signed-off-by: Christian Storm <christian.storm@siemens.com>\n> ---\n>  core/swupdate.c | 20 ++++++++++++++++++++\n>  1 file changed, 20 insertions(+)\n> \n> diff --git a/core/swupdate.c b/core/swupdate.c\n> index b01aadd..1f0ba0d 100644\n> --- a/core/swupdate.c\n> +++ b/core/swupdate.c\n> @@ -599,6 +599,13 @@ int main(int argc, char **argv)\n>  \t/* Process options with getopt */\n>  \twhile ((c = getopt_long(argc, argv, main_options,\n>  \t\t\t\tlong_options, NULL)) != EOF) {\n> +\t\tif (optarg && *optarg == '-' && (c != 'd' && c != 'u' && c != 'w')) {\n> +\t\t\t/* An option's value starting with '-' is not allowed except\n> +\t\t\t * for downloader, webserver, and suricatta doing their own\n> +\t\t\t * argv parsing.\n> +\t\t\t */\n> +\t\t\tc = '?';\n> +\t\t}\n>  \t\tswitch (c) {\n>  \t\tcase 'v':\n>  \t\t\tloglevel = TRACELEVEL;\n> @@ -680,6 +687,12 @@ int main(int argc, char **argv)\n>  \t\t}\n>  \t}\n>  \n> +\tif (optind < argc) {\n> +\t\t/* SWUpdate has no non-option arguments, fail on them */\n> +\t\tusage(argv[0]);\n> +\t\texit(1);\n> +\t}\n> +\n>  \t/*\n>  \t * Parameters are parsed: now performs plausibility\n>  \t * tests before starting processes and threads\n> @@ -698,6 +711,13 @@ int main(int argc, char **argv)\n>  \t\texit(1);\n>  \t}\n>  \n> +#ifdef CONFIG_SURICATTA\n> +\tif (opt_u && (opt_c || opt_i)) {\n> +\t\tfprintf(stderr, \"invalid mode combination with suricatta.\\n\");\n> +\t\texit(1);\n> +\t}\n> +#endif\n> +\n>  \tswupdate_crypto_init();\n>  \n>  \tif (strlen(swcfg.globals.publickeyfname)) {\n> \n\nApplied to -master, thanks !\n\nBest regards,\nStefano Babic","headers":{"Return-Path":"<swupdate+bncBAABBIU5WTGQKGQEJ43K3BY@googlegroups.com>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=googlegroups.com\n\t(client-ip=2a00:1450:400c:c09::238;\n\thelo=mail-wm0-x238.google.com;\n\tenvelope-from=swupdate+bncbaabbiu5wtgqkgqej43k3by@googlegroups.com;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=googlegroups.com header.i=@googlegroups.com\n\theader.b=\"Y3pRumiH\"; dkim-atps=neutral"],"Received":["from mail-wm0-x238.google.com (mail-wm0-x238.google.com\n\t[IPv6:2a00:1450:400c:c09::238])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xm2zs0Fbkz9s7m\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 18:28:23 +1000 (AEST)","by mail-wm0-x238.google.com with SMTP id z74sf1400177wmz.20\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 04 Sep 2017 01:28:23 -0700 (PDT)","by 10.28.11.203 with SMTP id 194ls1220973wml.6.canary-gmail;\n\tMon, 04 Sep 2017 01:28:18 -0700 (PDT)","from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.10])\n\tby gmr-mx.google.com with ESMTPS id\n\tk21si616892wmh.0.2017.09.04.01.28.18\n\tfor <swupdate@googlegroups.com>\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 04 Sep 2017 01:28:18 -0700 (PDT)","from frontend01.mail.m-online.net (unknown [192.168.8.182])\n\tby mail-out.m-online.net (Postfix) with ESMTP id 3xm2zk0mWBz1qw7J;\n\tMon,  4 Sep 2017 10:28:18 +0200 (CEST)","from localhost (dynscan1.mnet-online.de [192.168.6.70])\n\tby mail.m-online.net (Postfix) with ESMTP id 3xm2zk0LMyz3hhjf;\n\tMon,  4 Sep 2017 10:28:18 +0200 (CEST)","from mail.mnet-online.de ([192.168.8.182])\n\tby localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new,\n\tport 10024)\n\twith ESMTP id dX8UVskL8aXO; Mon,  4 Sep 2017 10:28:16 +0200 (CEST)","from babic.homelinux.org\n\t(host-88-217-136-221.customer.m-online.net [88.217.136.221])\n\t(using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mail.mnet-online.de (Postfix) with ESMTPS;\n\tMon,  4 Sep 2017 10:28:16 +0200 (CEST)","from localhost (mail.babic.homelinux.org [127.0.0.1])\n\tby babic.homelinux.org (Postfix) with ESMTP id AD4964540594;\n\tMon,  4 Sep 2017 10:28:15 +0200 (CEST)","from babic.homelinux.org ([127.0.0.1])\n\tby localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new,\n\tport 10024)\n\twith ESMTP id SI6ogNtYX0hB; Mon,  4 Sep 2017 10:28:13 +0200 (CEST)","from [192.168.178.132] (papero.fritz.box [192.168.178.132])\n\tby babic.homelinux.org (Postfix) with ESMTP id 14DD245403C3;\n\tMon,  4 Sep 2017 10:28:13 +0200 (CEST)"],"ARC-Seal":["i=2; a=rsa-sha256; t=1504513698; cv=pass;\n\td=google.com; s=arc-20160816;\n\tb=w9dTSTTyWVf+vCtQUzTWI0h3stcwEAb3mXoR/pfbZjfwTbwsN4AjmqDBEjMaGiEQ1z\n\tqUpg1WOVkX09OD5E7+ngmh1I3wkpzR+ojfOIuOnqIKhVutww3nq1mg3W91aLEv/t+IWo\n\t4YHylQJQHZd/roOcn7fGqU/AODsngKEHQ4OaQfI0nJEuHpG6PKp5GyNWSPzlc+OIcb/3\n\taYBgqmH/tnkCxu2eZHsHVRCzWXiEyvIzwY/uohcEX4gdInEXcWnN18W2dFVPERmKg0OG\n\tQpUmX92JT3rZ0pvbnVPdu3I3FRSOsjQyyRWBPsAigREnBk/VmnhE6RuYl2xwJ6d6Nryy\n\teaaw==","i=1; a=rsa-sha256; t=1504513698; cv=none;\n\td=google.com; s=arc-20160816;\n\tb=OB9GxhuqEOKThhsJ+y2ECT9uiC0WUnt8ZS+LoD6P/xNXcwNuFI6mGv2ZmjaMkU/Tbj\n\tBZ9O9GdrsVRWVf4r5j0WXD7nccRmrPVvBeCAHAGHn2PH8lVhfRJtu45IwN87r1yeqXm9\n\tdDiO9j5IXNgF2vv6ZOB9vndVL7ruhGRCKm6wmQuCeA7QybKkXVor52ejMll4Ls0fhziB\n\truFLFLDILJ5wHFcRahqrDub1wq3X/QxR8IoCF9wcDKhh/udcnpOwAkj3eQVGkFfnoaI1\n\tX42k3AgpHRXB9z1Y9VNe+TIj/oqLegPAbvOWo0mCooV17mejmNuVHkF3Nwn8udP6xJZw\n\tOxow=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=arc-20160816; \n\th=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n\t:list-id:mailing-list:precedence:content-language:in-reply-to\n\t:mime-version:user-agent:date:message-id:from:references:to:subject\n\t:arc-authentication-results:arc-message-signature:sender\n\t:dkim-signature:arc-authentication-results;\n\tbh=ugq4Xtc5CmJNDMqi8JdTC3ZM3GQ0XcxMr4yighktaPc=;\n\tb=NdB3IAVeObDT7J6Z1IndrWRSeVi8EhY2RvxqrpDMNFg8vRr6kiuEiY4rCJEiS/qIrB\n\t0rMjo2Ddg+PZ09Sh+UcGOvH3eZQVDM6NOaMWpc2hov6Z8jxhqDFjjVJekvEKQ5/QIm1d\n\tVUiVLbcLrRp4+vN5R1ALco4sDHqhvTzqLgGCOWngl6XXSuYKAWarHlVR3YS5X6gXTFXa\n\tgXgTkgpk8E4HMPbO8MtBmYGH+HbrqkwsYiogiOJ4V+HEY8SILnL0dTL7oDVhRk9GT+Jf\n\tVfymMinmWME5r4QjhjENm4UWOwhAIr3A17CYvi0EMUl3MdIkAyzHGoGKvmeDmBwK43td\n\tZvEA==","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=arc-20160816; \n\th=content-transfer-encoding:content-language:in-reply-to:mime-version\n\t:user-agent:date:message-id:from:references:to:subject\n\t:arc-authentication-results;\n\tbh=clDwg7OveKj7wkMDHB1ziyyZeqfPFWrzMKeTR2d8D8U=;\n\tb=umpv2BliGiJeM0vffiPj0HSpvlF3Oqi83MFScummVIV4kS8USPdtaYkzVilLJPMEDW\n\tT44guGNLrG5akp7dvhv4gzWUBaVqLMfp9pIQ5KnaECZO9rmBfC5DDH2AebQLLtmNapHw\n\tRF0nGGrN6a16trCuDcRHvZR4agRagZxbRfUX8Hluwn5lGrdS/8QjVkLx4qk+BzbGna2W\n\tHpnl8VGvAFiYd0tgxqV7SOuf8GWFQKyGKP0VvreZIY6T+/+HvI9DGyvvNJYYMbmiiNc1\n\tEI+ja66vA2IkgzIRDiFtV7XO7U5eKroLRzNcthjUISGJUBGmeSFXYUgw9ouCFOCPUHWc\n\tI9Tg=="],"ARC-Authentication-Results":["i=2; gmr-mx.google.com;\n\tspf=neutral (google.com: 212.18.0.10 is neither permitted nor denied\n\tby best guess record for domain of sbabic@denx.de)\n\tsmtp.mailfrom=sbabic@denx.de","i=1; gmr-mx.google.com;\n\tspf=neutral (google.com: 212.18.0.10 is neither permitted nor denied\n\tby best guess record for domain of sbabic@denx.de)\n\tsmtp.mailfrom=sbabic@denx.de"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=googlegroups.com; s=20161025;\n\th=sender:subject:to:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:x-original-sender\n\t:x-original-authentication-results:precedence:mailing-list:list-id\n\t:list-post:list-help:list-archive:list-subscribe:list-unsubscribe;\n\tbh=ugq4Xtc5CmJNDMqi8JdTC3ZM3GQ0XcxMr4yighktaPc=;\n\tb=Y3pRumiHNPLDPFKQZe3zySmTg/gV+tG5tcnZZg/F3YjogEY8GZ58rYhfAR5Xca8zOB\n\tW6dD6Ua0vWRCpc2SkhYb4d0kV+7fcLYFalrHiVeHDqI8ifhq+eVueyNmAoqC3gysuHge\n\tYIRFtFbG8vvlnzcGIp7LcEgijeU3uK/ZpQdUH8KI4dWF1ESwNqt1i+KhAwU+sM9cX2S6\n\tiYZh30ws2h2ZWlXedi6VlReXVLOtzQ0392jeFRFeHrOVV9fYSKgE9LUcjoopOGt9DyaE\n\tUknL6Ki3AsYzg9Z/xVfo1e/cb7xV1rZDOIqlKIri3cNN+XlbFZvp7gvgVUJTnoAiLJjP\n\tQ4TA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=sender:x-gm-message-state:subject:to:references:from:message-id\n\t:date:user-agent:mime-version:in-reply-to:content-language\n\t:x-original-sender:x-original-authentication-results:precedence\n\t:mailing-list:list-id:x-spam-checked-in-group:list-post:list-help\n\t:list-archive:list-subscribe:list-unsubscribe;\n\tbh=ugq4Xtc5CmJNDMqi8JdTC3ZM3GQ0XcxMr4yighktaPc=;\n\tb=Drf5Lr9uz09E/kM+IYX6MlcJqpYgXzQi+yEPEClOcUGoFKkhWOiHrf6ryXwrzreRxA\n\tYF2wcG6ywRrm42LJ5HO1mHZhpfVFOwupR05Tfua54hzllXOnyIp4l0XRYAPRFR4Pjs+a\n\tZIRhxOD/6A6YJWxkVQnSDE82xirkSTey/a2PA4I7LuC13ry9LeIkvixWOYKljfccc46o\n\t1aKQULWCr1iYTvVf5ZFD/3JpVZ5roy9XuWanC61wd/LN8VtnJMXjBah9Rg+u554QW3WX\n\t5Ahys55vaOmquJbfAoMQAv6ZNvuXJZ6Qj1/l/QhbhL4Mmr9duQVsD0MUPuNVrhi6kDV4\n\ti0xg==","Sender":"swupdate@googlegroups.com","X-Gm-Message-State":"AHPjjUgWRZWHzeG3DUuQ1yG4VCAAhPkBsECq+G8Iy5n9dM2OmMlV2JFM\n\tXBUC4gm/f4OGeA==","X-Google-Smtp-Source":"ADKCNb6L0hf2nDOLubn/Oss1Jv7fhyrXSzfVFZVXC1Fxhmji4gngHy9IMZTDyMlqG7JOgQ6TuV6t3w==","X-Received":["by 10.28.193.142 with SMTP id r136mr24499wmf.1.1504513698663;\n\tMon, 04 Sep 2017 01:28:18 -0700 (PDT)","by 10.28.150.22 with SMTP id y22mr2095wmd.24.1504513698332;\n\tMon, 04 Sep 2017 01:28:18 -0700 (PDT)"],"X-BeenThere":"swupdate@googlegroups.com","Received-SPF":"neutral (google.com: 212.18.0.10 is neither permitted nor\n\tdenied by best guess record for domain of sbabic@denx.de)\n\tclient-ip=212.18.0.10; ","X-Virus-Scanned":["amavisd-new at mnet-online.de","Debian amavisd-new at babic.homelinux.org"],"Subject":"Re: [swupdate] [PATCH v2] core: make cmdline parsing more robust","To":"Christian Storm <christian.storm@siemens.com>, swupdate@googlegroups.com","References":"<2a9c51d7-a92a-09b9-27a2-89bee07c5f17@denx.de>\n\t<20170831103601.13500-1-christian.storm@siemens.com>","From":"Stefano Babic <sbabic@denx.de>","Message-ID":"<225b739e-6343-9236-1a58-e90ff87aab53@denx.de>","Date":"Mon, 4 Sep 2017 10:28:13 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<20170831103601.13500-1-christian.storm@siemens.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Language":"de-DE","X-Original-Sender":"sbabic@denx.de","X-Original-Authentication-Results":"gmr-mx.google.com;       spf=neutral\n\t(google.com: 212.18.0.10 is neither permitted nor denied by best\n\tguess record\n\tfor domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de","Precedence":"list","Mailing-list":"list swupdate@googlegroups.com;\n\tcontact swupdate+owners@googlegroups.com","List-ID":"<swupdate.googlegroups.com>","X-Spam-Checked-In-Group":"swupdate@googlegroups.com","X-Google-Group-Id":"605343134186","List-Post":"<https://groups.google.com/group/swupdate/post>,\n\t<mailto:swupdate@googlegroups.com>","List-Help":"<https://groups.google.com/support/>,\n\t<mailto:swupdate+help@googlegroups.com>","List-Archive":"<https://groups.google.com/group/swupdate","List-Subscribe":"<https://groups.google.com/group/swupdate/subscribe>,\n\t<mailto:swupdate+subscribe@googlegroups.com>","List-Unsubscribe":"<mailto:googlegroups-manage+605343134186+unsubscribe@googlegroups.com>,\n\t<https://groups.google.com/group/swupdate/subscribe>"}}]