Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb55e95

Browse files
committed
Avoid platform-specific null pointer dereference in psql.
POSIX permits getopt() to advance optind beyond argc when the lastargv entry is an option that requires an argument and hasn't got one.It seems that no major platforms actually do that, but musl does,so that something like "psql -f" would crash with that libc.Add a check that optind is in range before trying to look at thepossibly-bogus option.Report and fix by Quentin Rameau. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/20190825100617.GA6087@fifth.space
1 parent1fb2d78 commitfb55e95

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

‎src/bin/psql/startup.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,15 +619,18 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
619619
options->single_txn= true;
620620
break;
621621
case'?':
622-
/* Actual help option given */
623-
if (strcmp(argv[optind-1],"-?")==0)
622+
if (optind <=argc&&
623+
strcmp(argv[optind-1],"-?")==0)
624624
{
625+
/* actual help option given */
625626
usage(NOPAGER);
626627
exit(EXIT_SUCCESS);
627628
}
628-
/* unknown option reported by getopt */
629629
else
630+
{
631+
/* getopt error (unknown option or missing argument) */
630632
gotounknown_option;
633+
}
631634
break;
632635
case1:
633636
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp