Skip to content

Commit 8d15e3e

Browse files
committed
Don't forget to de-escape the password field in .pgpass.
This has been broken just about forever (or more specifically, commit 7f4981f) and nobody noticed until Richard Huxton reported it recently. Analysis and fix by Ross Reedstrom, although I didn't use his patch. This doesn't seem important enough to back-patch and is mildly backward incompatible, so I'm just doing this in master.
1 parent c31224e commit 8d15e3e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4904,7 +4904,9 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
49044904
while (!feof(fp) && !ferror(fp))
49054905
{
49064906
char *t = buf,
4907-
*ret;
4907+
*ret,
4908+
*p1,
4909+
*p2;
49084910
int len;
49094911

49104912
if (fgets(buf, sizeof(buf), fp) == NULL)
@@ -4925,6 +4927,16 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
49254927
continue;
49264928
ret = strdup(t);
49274929
fclose(fp);
4930+
4931+
/* De-escape password. */
4932+
for (p1 = p2 = ret; *p1 != ':' && *p1 != '\0'; ++p1, ++p2)
4933+
{
4934+
if (*p1 == '\\' && p1[1] != '\0')
4935+
++p1;
4936+
*p2 = *p1;
4937+
}
4938+
*p2 = '\0';
4939+
49284940
return ret;
49294941
}
49304942

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy