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

Commit2ac5988

Browse files
committed
Fix misparsing of non-newline-terminated pg_hba.conf files.
This back-patches the v10-cycle commit1e5a5d0 into 9.3 - 9.6.I had noticed at the time that that was fixing a bug, namely thatnext_token() might advance *lineptr past the line-terminating '\0',but given the lack of field complaints I too easily convinced myselfthat the problem was only latent. It's not, because tokenize_file()decides whether there's more on the line using "strlen(lineptr)".The bug is indeed latent on a newline-terminated line, because thenthe newline-stripping bit in tokenize_file() means we'll have twoor more consecutive '\0's in the buffer, masking the fact that weaccidentally advanced over the first one. But the last line inthe file might not be null-terminated, allowing the loop to seeand process garbage, as reported by Mark Jones in bug #14859.The bug doesn't exist in <= 9.2; there next_token() is reading directlyfrom a file, and termination of the outer loop relies on an feof() testnot a buffer pointer check. Probably commit7f49a67 can be blamedfor this bug, but I didn't track it down exactly.Commit1e5a5d0 does a bit more than the minimum needed to fix thebug, but I felt the rest of it was good cleanup, so applying it all.Discussion:https://postgr.es/m/20171017141814.8203.27280@wrigleys.postgresql.org
1 parentaa1e9b3 commit2ac5988

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

‎src/backend/libpq/hba.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,42 +141,32 @@ next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote,
141141
{
142142
intc;
143143
char*start_buf=buf;
144-
char*end_buf=buf+ (bufsz-2);
144+
char*end_buf=buf+ (bufsz-1);
145145
boolin_quote= false;
146146
boolwas_quote= false;
147147
boolsaw_quote= false;
148148

149-
/* end_buf reserves two bytes to ensure we can append \n and \0 */
150149
Assert(end_buf>start_buf);
151150

152151
*initial_quote= false;
153152
*terminating_comma= false;
154153

155-
/* Move overinitial whitespace and commas */
154+
/* Move overany whitespace and commas preceding the next token */
156155
while ((c= (*(*lineptr)++))!='\0'&& (pg_isblank(c)||c==','))
157156
;
158157

159-
if (c=='\0'||c=='\n')
160-
{
161-
*buf='\0';
162-
return false;
163-
}
164-
165158
/*
166-
* Build a token in buf of next characters up toEOF,EOL, unquoted comma,
167-
*orunquoted whitespace.
159+
* Build a token in buf of next characters up to EOL, unquoted comma, or
160+
* unquoted whitespace.
168161
*/
169-
while (c!='\0'&&c!='\n'&&
162+
while (c!='\0'&&
170163
(!pg_isblank(c)||in_quote))
171164
{
172165
/* skip comments to EOL */
173166
if (c=='#'&& !in_quote)
174167
{
175-
while ((c= (*(*lineptr)++))!='\0'&&c!='\n')
168+
while ((c= (*(*lineptr)++))!='\0')
176169
;
177-
/* If only comment, consume EOL too; return EOL */
178-
if (c!='\0'&&buf==start_buf)
179-
(*lineptr)++;
180170
break;
181171
}
182172

@@ -188,12 +178,12 @@ next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote,
188178
errmsg("authentication file token too long, skipping: \"%s\"",
189179
start_buf)));
190180
/* Discard remainder of line */
191-
while ((c= (*(*lineptr)++))!='\0'&&c!='\n')
181+
while ((c= (*(*lineptr)++))!='\0')
192182
;
193183
break;
194184
}
195185

196-
/* we do not pass backthe comma in the token */
186+
/* we do not pass backa terminating comma in the token */
197187
if (c==','&& !in_quote)
198188
{
199189
*terminating_comma= true;
@@ -221,8 +211,8 @@ next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote,
221211
}
222212

223213
/*
224-
*Put backthe char right after the token (critical in case it isEOL,
225-
*since we need to detectend-of-line at next call).
214+
*Un-eatthe char right after the token (critical in case it is'\0',
215+
*else next call will read pastend of string).
226216
*/
227217
(*lineptr)--;
228218

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp