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

Commit11a0a4d

Browse files
committed
Fix failures to ignore \r when reading Windows-style newlines.
libpq failed to ignore Windows-style newlines in connection service files.This normally wasn't a problem on Windows itself, because fgets() wouldconvert \r\n to just \n. But if libpq were running inside a program thatchanges the default fopen mode to binary, it would see the \r's and thinkthey were data. In any case, it's project policy to ignore \r in textfiles unconditionally, because people sometimes try to use files withDOS-style newlines on Unix machines, where the C library won't hide thatfrom us.Hence, adjust parseServiceFile() to ignore \r as well as \n at the end ofthe line. In HEAD, go a little further and make it ignore all trailingwhitespace, to match what it's always done with leading whitespace.In HEAD, also run around and fix up everyplace where we havenewline-chomping code to make all those places look consistent anduniformly drop \r. It is not clear whether any of those changes arefixing live bugs. Most of the non-cosmetic changes are in places thatare reading popen output, and the jury is still out as to whether popenon Windows can return \r\n. (The Windows-specific code in pipe_read_lineseems to think so, but our lack of support for this elsewhere suggestsmaybe it's not a problem in practice.) Hence, I desisted from applyingthose changes to back branches, except in run_ssl_passphrase_command()which is new enough and little-tested enough that we'd probably not haveheard about any problems there.Tom Lane and Michael Paquier, per bug #15827 from Jorge Gustavo Rocha.Back-patch the parseServiceFile() change to all supported branches,and the run_ssl_passphrase_command() change to v11 where that was added.Discussion:https://postgr.es/m/15827-e6ba53a3a7ed543c@postgresql.org
1 parentfe9e632 commit11a0a4d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

‎src/backend/libpq/be-secure-common.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf,
112112
gotoerror;
113113
}
114114

115-
/* strip trailing newline */
115+
/* strip trailing newline, including \r in case we're on Windows */
116116
len=strlen(buf);
117-
if (len>0&&buf[len-1]=='\n')
117+
while (len>0&& (buf[len-1]=='\n'||
118+
buf[len-1]=='\r'))
118119
buf[--len]='\0';
119120

120121
error:

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4661,6 +4661,8 @@ parseServiceFile(const char *serviceFile,
46614661

46624662
while ((line=fgets(buf,sizeof(buf),f))!=NULL)
46634663
{
4664+
intlen;
4665+
46644666
linenr++;
46654667

46664668
if (strlen(line) >=sizeof(buf)-1)
@@ -4673,16 +4675,18 @@ parseServiceFile(const char *serviceFile,
46734675
return2;
46744676
}
46754677

4676-
/* ignore EOL at end of line */
4677-
if (strlen(line)&&line[strlen(line)-1]=='\n')
4678-
line[strlen(line)-1]=0;
4678+
/* ignore EOL at end of line, including \r in case it's a DOS file */
4679+
len=strlen(line);
4680+
while (len>0&& (line[len-1]=='\n'||
4681+
line[len-1]=='\r'))
4682+
line[--len]='\0';
46794683

46804684
/* ignore leading blanks */
46814685
while (*line&&isspace((unsignedchar)line[0]))
46824686
line++;
46834687

46844688
/* ignore comments and empty lines */
4685-
if (strlen(line)==0||line[0]=='#')
4689+
if (line[0]=='\0'||line[0]=='#')
46864690
continue;
46874691

46884692
/* Check for right groupname */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp