mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Don't forget to de-escape the password field in .pgpass.
This has been broken just about forever (or more specifically, commit
7f4981f4af) 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.
This commit is contained in:
@@ -4904,7 +4904,9 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
|
||||
while (!feof(fp) && !ferror(fp))
|
||||
{
|
||||
char *t = buf,
|
||||
*ret;
|
||||
*ret,
|
||||
*p1,
|
||||
*p2;
|
||||
int len;
|
||||
|
||||
if (fgets(buf, sizeof(buf), fp) == NULL)
|
||||
@@ -4925,6 +4927,16 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
|
||||
continue;
|
||||
ret = strdup(t);
|
||||
fclose(fp);
|
||||
|
||||
/* De-escape password. */
|
||||
for (p1 = p2 = ret; *p1 != ':' && *p1 != '\0'; ++p1, ++p2)
|
||||
{
|
||||
if (*p1 == '\\' && p1[1] != '\0')
|
||||
++p1;
|
||||
*p2 = *p1;
|
||||
}
|
||||
*p2 = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user