aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/libpq/fe-connect.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index b4f9ad72e59..ae85db9dd5a 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -6026,18 +6026,26 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
break;
len = strlen(buf);
- if (len == 0)
- continue;
/* Remove trailing newline */
- if (buf[len - 1] == '\n')
- buf[len - 1] = 0;
+ if (len > 0 && buf[len - 1] == '\n')
+ {
+ buf[--len] = '\0';
+ /* Handle DOS-style line endings, too, even when not on Windows */
+ if (len > 0 && buf[len - 1] == '\r')
+ buf[--len] = '\0';
+ }
+
+ if (len == 0)
+ continue;
if ((t = pwdfMatchesString(t, hostname)) == NULL ||
(t = pwdfMatchesString(t, port)) == NULL ||
(t = pwdfMatchesString(t, dbname)) == NULL ||
(t = pwdfMatchesString(t, username)) == NULL)
continue;
+
+ /* Found a match. */
ret = strdup(t);
fclose(fp);