]> granicus.if.org Git - postgresql/commit
Fix simple_prompt() to disable echo on Windows when stdin != terminal.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 May 2018 23:04:34 +0000 (19:04 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 May 2018 23:04:34 +0000 (19:04 -0400)
commitbbaf75ee0c3aa902f6d8935eb3f433149a461144
treed205d290e5dfa33e6d8a401f282fa6b780599934
parent588edd83e541c421dafa85ed6ba2a04dab5af984
Fix simple_prompt() to disable echo on Windows when stdin != terminal.

If echo = false, simple_prompt() is supposed to prevent echoing the
input (for password input).  However, the Windows implementation applied
the mode change to STD_INPUT_HANDLE.  That would not have the desired
effect if stdin isn't actually the terminal, for instance if the user
is piping something into psql.  Fix it to apply the mode change to
the correct input file, so that passwords do not echo in such cases.

In passing, shorten and de-uglify this code by using #elif rather than
an #if nest and removing some duplicated code.

Back-patch to all supported versions.  To simplify that, also back-patch
the portions of commit 9daec77e1 that got rid of an unnecessary
malloc/free in the same area.

Matthew Stickney (cosmetic changes by me)

Discussion: https://postgr.es/m/502a1fff-862b-da52-1031-f68df6ed5a2d@gmail.com
src/port/sprompt.c