Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i1pPo-0007fk-OX for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Aug 2019 10:06:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i1pPl-00073L-Ga for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Aug 2019 10:06:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i1pPk-0006yk-VT for pgsql-hackers@lists.postgresql.org; Sun, 25 Aug 2019 10:06:25 +0000 Received: from fifth.space ([45.32.148.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i1pPf-0003I1-El for pgsql-hackers@postgresql.org; Sun, 25 Aug 2019 10:06:24 +0000 Received: from fifth.space (localhost [127.0.0.1]) by fifth.space (OpenSMTPD) with ESMTP id 5fff8460 for ; Sun, 25 Aug 2019 12:06:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=fifth.space; h=date:from :to:subject:message-id:mime-version:content-type; s=dkim; bh=HQK fxeq7Oi6a7Ss1Y5Ggj0j3Wf4=; b=LAq/tlaMG6l4bdkYTuu3cm574UePVTC15sb 3s6G1W0I/B9q8/Qq88UM4fGwzqit9UqnH1+SfuzcnIDLgKcN+IJUXniHG7DM6QcZ 1x3lKCsd4Ier6Vu25NW+c73Au7tD3VkvfMIxi5upigM0nsDblJ/JBiqDwlfBYGhw vsvsB3iafyiU6a6cGulbrWzizA/NWyWoE2Zb69dI9nZdZ+x3APOoXC0P0fsrwXfS 02A07cFPK94DHg/wwl4XE4otzlUUrf/g4u4hVtMDEB2R/xTZ5EcQT+arltyi9dFP FSvY6URxty0s/MdqGxJS1b5B9+xi+iotGctHjKKFSxTsZFEQwJg== DomainKey-Signature: a=rsa-sha1; c=nofws; d=fifth.space; h=date:from:to :subject:message-id:mime-version:content-type; q=dns; s=dkim; b= QpLJKFAUudhJSSN98014FlkiH4CK5YLSB7HzxdoMHg2TthRd3uN3LKS3VZw3YhdK X8awKXheNU+FeGj/DVKGD3Qgqp9WAiFjGY5LqG+gSUBkr+x7erfPSSEMVunOLEq7 an/LSBWCXaV8uT3YuTdyVFZ+kclwY2Xv8DSJSwuSGaFQbRSg/L1LF6i0r7KNopVB 0w9qAu4bMTzAVL4Du3ycNlCkXONC+IocJLj35wB5ckDhG0E8XxvEUnPdWPofezX2 w/GoVxoKpi+xISdMM6FGZ4iM6IFMhYkubk2YBEFAJE8Rs3InmvIngVRhD9dnrBVG znS3pica1rxlhy1sxDPrGA== Received: from localhost (fifth.space [local]) by fifth.space (OpenSMTPD) with ESMTPA id cc75013e for ; Sun, 25 Aug 2019 12:06:17 +0200 (CEST) Date: Sun, 25 Aug 2019 12:06:17 +0200 From: Quentin Rameau To: pgsql-hackers@postgresql.org Subject: [PATCH] Fix missing argument handling in psql getopt Message-ID: <20190825100617.GA6087@fifth.space> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.11.4 (2019-03-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk When passing an argument option with a missing argument, strcmp would be called with the argv terminating NULL. --- src/bin/psql/startup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 4730c73396..cffbfc864e 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -667,12 +667,13 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options) break; case '?': /* Actual help option given */ - if (strcmp(argv[optind - 1], "-?") == 0) + if (optind <= argc && + strcmp(argv[optind - 1], "-?") == 0) { usage(NOPAGER); exit(EXIT_SUCCESS); } - /* unknown option reported by getopt */ + /* unknown option or missing argument */ else goto unknown_option; break; -- 2.23.0