You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Teach libpq to handle arbitrary-length lines in .pgpass files.
Historically there's been a hard-wired assumption here that no line of
a .pgpass file could be as long as NAMEDATALEN*5 bytes. That's a bit
shaky to start off with, because (a) there's no reason to suppose that
host names fit in NAMEDATALEN, and (b) this figure fails to allow for
backslash escape characters. However, it fails completely if someone
wants to use a very long password, and we're now hearing reports of
people wanting to use "security tokens" that can run up to several
hundred bytes. Another angle is that the file is specified to allow
comment lines, but there's no reason to assume that long comment lines
aren't possible.
Rather than guessing at what might be a more suitable limit, let's
replace the fixed-size buffer with an expansible PQExpBuffer. That
adds one malloc/free cycle to the typical use-case, but that's surely
pretty cheap relative to the I/O this code has to do.
Also, add TAP test cases to exercise this code, because there was no
test coverage before.
This reverts most of commit 2eb3bc5, as there's no longer a need for
a warning message about overlength .pgpass lines. (I kept the explicit
check for comment lines, though.)
In HEAD and v13, this also fixes an oversight in 74a308c: there's not
much point in explicit_bzero'ing the line buffer if we only do so in two
of the three exit paths.
Back-patch to all supported branches, except that the test case only
goes back to v10 where src/test/authentication/ was added.
Discussion: https://postgr.es/m/4187382.1598909041@sss.pgh.pa.us
# Test .pgpass processing; but use a temp file, don't overwrite the real one!
103
+
my$pgpassfile = "${TestLib::tmp_check}/pgpass";
104
+
105
+
delete$ENV{"PGPASSWORD"};
106
+
delete$ENV{"PGCHANNELBINDING"};
107
+
$ENV{"PGPASSFILE"} = $pgpassfile;
108
+
109
+
append_to_file($pgpassfile, qq!
110
+
# This very long comment is just here to exercise handling of long lines in the file. This very long comment is just here to exercise handling of long lines in the file. This very long comment is just here to exercise handling of long lines in the file. This very long comment is just here to exercise handling of long lines in the file. This very long comment is just here to exercise handling of long lines in the file.
111
+
*:*:postgres:scram_role:pass:this is not part of the password.
112
+
!);
113
+
chmod 0600, $pgpassfileordie;
114
+
115
+
reset_pg_hba($node, 'password');
116
+
test_role($node, 'scram_role', 'password from pgpass', 0);
117
+
test_role($node, 'md5_role', 'password from pgpass', 2);
118
+
119
+
append_to_file($pgpassfile, qq!
120
+
*:*:*:md5_role:p\\ass
121
+
!);
122
+
123
+
test_role($node, 'md5_role', 'password from pgpass', 0);
0 commit comments