Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a74819

Browse files
committed
Allow DOS-style line endings in ~/.pgpass files.
On Windows, libc will mask \r\n line endings for us, since we read thepassword file in text mode. But that doesn't happen on Unix. Peoplewho share password files across both systems might have \r\n line endingsin a file they use on Unix, so as a convenience, ignore trailing \r.Per gripe from Josh Berkus.In passing, put the existing check for empty line somewhere where it'sactually useful, ie after stripping the newline not before.Vik Fearing, adjusted a bit by meDiscussion: <0de37763-5843-b2cc-855e-5d0e5df25807@agliodbs.com>
1 parentffaa44c commit0a74819

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6026,18 +6026,26 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
60266026
break;
60276027

60286028
len=strlen(buf);
6029-
if (len==0)
6030-
continue;
60316029

60326030
/* Remove trailing newline */
6033-
if (buf[len-1]=='\n')
6034-
buf[len-1]=0;
6031+
if (len>0&&buf[len-1]=='\n')
6032+
{
6033+
buf[--len]='\0';
6034+
/* Handle DOS-style line endings, too, even when not on Windows */
6035+
if (len>0&&buf[len-1]=='\r')
6036+
buf[--len]='\0';
6037+
}
6038+
6039+
if (len==0)
6040+
continue;
60356041

60366042
if ((t=pwdfMatchesString(t,hostname))==NULL||
60376043
(t=pwdfMatchesString(t,port))==NULL||
60386044
(t=pwdfMatchesString(t,dbname))==NULL||
60396045
(t=pwdfMatchesString(t,username))==NULL)
60406046
continue;
6047+
6048+
/* Found a match. */
60416049
ret=strdup(t);
60426050
fclose(fp);
60436051

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp