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

Commit2eb3bc5

Browse files
committed
Fix issues around .pgpass file.
This commit fixes the following two issues around .pgpass file.(1) If the length of a line in .pgpass file was larger than 319B, libpq silently treated each 319B in the line as a separate setting line.(2) The document explains that a line beginning with # is treated as a comment in .pgpass. But there was no code doing such special handling. Whether a line begins with # or not, libpq just checked that the first token in the line match with the host.For (1), this commit makes libpq warn if the length of a lineis larger than 319B, and throw away the remaining part beginningfrom 320B position.For (2), this commit changes libpq so that it treats any linesbeginning with # as comments.Author: Fujii MasaoReviewed-by: Hamid AkhtarDiscussion:https://postgr.es/m/c0f0c01c-fa74-9749-2084-b73882fd5465@oss.nttdata.com
1 parentfbcf087 commit2eb3bc5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6949,6 +6949,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
69496949
{
69506950
FILE*fp;
69516951
structstatstat_buf;
6952+
intline_number=0;
69526953

69536954
#defineLINELEN NAMEDATALEN*5
69546955
charbuf[LINELEN];
@@ -7014,10 +7015,42 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
70147015
*p1,
70157016
*p2;
70167017
intlen;
7018+
intbuflen;
70177019

70187020
if (fgets(buf,sizeof(buf),fp)==NULL)
70197021
break;
70207022

7023+
line_number++;
7024+
buflen=strlen(buf);
7025+
if (buflen >=sizeof(buf)-1&&buf[buflen-1]!='\n')
7026+
{
7027+
charrest[LINELEN];
7028+
intrestlen;
7029+
7030+
/*
7031+
* Warn if this password setting line is too long, because it's
7032+
* unexpectedly truncated.
7033+
*/
7034+
if (buf[0]!='#')
7035+
fprintf(stderr,
7036+
libpq_gettext("WARNING: line %d too long in password file \"%s\"\n"),
7037+
line_number,pgpassfile);
7038+
7039+
/* eat rest of the line */
7040+
while (!feof(fp)&& !ferror(fp))
7041+
{
7042+
if (fgets(rest,sizeof(rest),fp)==NULL)
7043+
break;
7044+
restlen=strlen(rest);
7045+
if (restlen<sizeof(rest)-1||rest[restlen-1]=='\n')
7046+
break;
7047+
}
7048+
}
7049+
7050+
/* ignore comments */
7051+
if (buf[0]=='#')
7052+
continue;
7053+
70217054
/* strip trailing newline and carriage return */
70227055
len=pg_strip_crlf(buf);
70237056

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp