pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Quentin Rameau <quinq@fifth.space>
To: pgsql-hackers@postgresql.org
Subject: [PATCH] Fix missing argument handling in psql getopt
Date: Sun, 25 Aug 2019 12:06:17 +0200
Message-ID: <20190825100617.GA6087@fifth.space> (raw)

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






view thread (9+ messages)  latest in thread

Message-ID: <20190825100617.GA6087@fifth.space>
Permalink:  ../20190825100617.GA6087@fifth.space/
Also on:    postgresql.org/message-id/20190825100617.GA6087@fifth.space

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: quinq@fifth.space
  Subject: Re: [PATCH] Fix missing argument handling in psql getopt
  In-Reply-To: <20190825100617.GA6087@fifth.space>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox