]> granicus.if.org Git - postgresql/commit
Avoid platform-specific null pointer dereference in psql.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 25 Aug 2019 19:04:04 +0000 (15:04 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 25 Aug 2019 19:04:04 +0000 (15:04 -0400)
commit363382521eb26106587c7dab7f439636c3a6876a
treedd730af98e1fd5da820d287193681c8c338374bc
parentcd714b3507c914e78d47352d1e126b4bec4380ad
Avoid platform-specific null pointer dereference in psql.

POSIX permits getopt() to advance optind beyond argc when the last
argv 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 the
possibly-bogus option.

Report and fix by Quentin Rameau.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/20190825100617.GA6087@fifth.space
src/bin/psql/startup.c