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

Commit6338fa3

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 parentfaee5a1 commit6338fa3

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
@@ -666,15 +666,18 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
666666
options->single_txn= true;
667667
break;
668668
case'?':
669-
/* Actual help option given */
670-
if (strcmp(argv[optind-1],"-?")==0)
669+
if (optind <=argc&&
670+
strcmp(argv[optind-1],"-?")==0)
671671
{
672+
/* actual help option given */
672673
usage(NOPAGER);
673674
exit(EXIT_SUCCESS);
674675
}
675-
/* unknown option reported by getopt */
676676
else
677+
{
678+
/* getopt error (unknown option or missing argument) */
677679
gotounknown_option;
680+
}
678681
break;
679682
case1:
680683
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp