[PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
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 --

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
Hello Tom, > > When passing an argument option with a missing argument, strcmp > > would be called with the argv terminating NULL. > > Um ... so how would control get there with optind too large? That's from the getopt specification[0]: “If the option was the last character in the string poin

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
> > Um ... so how would control get there with optind too large? Sorry, I missed the simple explanation for that: As option 'h' is missing an argument, getopt(_long) returns the character '?' which is switched on through variable c, and the program jumps to the '?' case handling.

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
l > still does. Another better way, I think, to fix this is to check for optopt instead, which would be set to the option which caused the error, which if empty means there isn't an error. Patch attached. >From 8aaec7d151567385c43d8966f46f0e5e4837c93c Mon Sep 17 00:00:00 2001 From: Quentin Rameau Date: Sun, 25 Aug 2019

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
dated attached patch ensure we start with an empty optopt. >From ba0b331e67db4eb1a66ee7a1445a536f9788f0ad Mon Sep 17 00:00:00 2001 From: Quentin Rameau Date: Sun, 25 Aug 2019 20:45:29 +0200 Subject: [PATCH] Fix handling of ? option Using optind to check back the original given option th

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
> I've pushed your original patch (with some comment-tweaking). > It seems unlikely to break anything. Thanks!