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

Commit5fc7b1e

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 parentee18293 commit5fc7b1e

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
@@ -634,15 +634,18 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
634634
options->single_txn= true;
635635
break;
636636
case'?':
637-
/* Actual help option given */
638-
if (strcmp(argv[optind-1],"-?")==0)
637+
if (optind <=argc&&
638+
strcmp(argv[optind-1],"-?")==0)
639639
{
640+
/* actual help option given */
640641
usage(NOPAGER);
641642
exit(EXIT_SUCCESS);
642643
}
643-
/* unknown option reported by getopt */
644644
else
645+
{
646+
/* getopt error (unknown option or missing argument) */
645647
gotounknown_option;
648+
}
646649
break;
647650
case1:
648651
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp