libpq: Do not leave residue in result of passwordFromFile()

The result of passwordFromFile() copied the remainder of the matching
password file line with strdup() and then de-escaped the copy in place.
The copy held everything up to the end of the line, and every escape
sequence shrinks the string by one byte.  This kept some bytes around
still on the stack, like the tail of the escaped password, past the end
of the termination byte.

De-escape the password within the line buffer instead, which is cleared
with explicit_bzero() before it is freed, and copy only the de-escaped
password.  The returned string is unchanged, and the function now writes
nothing past its terminating zero byte.

No backpatch, as this sounds like an improvement and not a bug.

Reported-by: Denis Smirnov <[email protected]>
Author: Diego <[email protected]>
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7622c7db525377a924e7b7fce2b9c74bda7c9856

Modified Files
--------------
src/interfaces/libpq/fe-connect.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

Reply via email to