[PATCH] Fix missing argument handling in psql getopt
Quentin Rameau <quinq@fifth.space>
From: Quentin Rameau <quinq@fifth.space>
To: pgsql-hackers@postgresql.org
Date: 2019-08-25T10:06:17Z
Lists: pgsql-hackers
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
Commits
-
Avoid platform-specific null pointer dereference in psql.
- fb55e95396ca 10.11 landed
- c693c5c4904d 9.4.25 landed
- 65b1cad5a092 9.5.20 landed
- 6338fa3e715a 13.0 landed
- 5fc7b1e939c4 11.6 landed
- 363382521eb2 12.0 landed
- 28d2ce3c7c99 9.6.16 landed