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

Commit8b3e2c6

Browse files
committed
Fix pg_isblank()
There was a pg_isblank() function that claimed to be a replacement forthe standard isblank() function, which was thought to be "not veryportable yet". We can now assume that it's portable (it's in C99).But pg_isblank() actually diverged from the standard isblank() by alsoaccepting '\r', while the standard one only accepts space and tab.This was added to support parsing pg_hba.conf under Windows. But thehba parsing code now works completely differently and already handlesline endings before we get to pg_isblank(). The other user ofpg_isblank() is for ident protocol message parsing, which also handles'\r' separately. So this behavior is now obsolete and confusing.To improve clarity, I separated those concerns. The ident parsing nowgets its own function that hardcodes the whitespace charactersmentioned by the relevant RFC. pg_isblank() is now static in hba.cand is a wrapper around the standard isblank(), with some extra logicto ensure robust treatment of non-ASCII characters.Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://www.postgresql.org/message-id/flat/170308e6-a7a3-4484-87b2-f960bb564afa%40eisentraut.org
1 parente68b6ad commit8b3e2c6

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

‎src/backend/libpq/auth.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,15 @@ pg_SSPI_make_upn(char *accountname,
15801580
*----------------------------------------------------------------
15811581
*/
15821582

1583+
/*
1584+
* Per RFC 1413, space and tab are whitespace in ident messages.
1585+
*/
1586+
staticbool
1587+
is_ident_whitespace(constcharc)
1588+
{
1589+
returnc==' '||c=='\t';
1590+
}
1591+
15831592
/*
15841593
*Parse the string "*ident_response" as a response from a query to an Ident
15851594
*server. If it's a normal response indicating a user name, return true
@@ -1613,14 +1622,14 @@ interpret_ident_response(const char *ident_response,
16131622
inti;/* Index into *response_type */
16141623

16151624
cursor++;/* Go over colon */
1616-
while (pg_isblank(*cursor))
1625+
while (is_ident_whitespace(*cursor))
16171626
cursor++;/* skip blanks */
16181627
i=0;
1619-
while (*cursor!=':'&&*cursor!='\r'&& !pg_isblank(*cursor)&&
1628+
while (*cursor!=':'&&*cursor!='\r'&& !is_ident_whitespace(*cursor)&&
16201629
i< (int) (sizeof(response_type)-1))
16211630
response_type[i++]=*cursor++;
16221631
response_type[i]='\0';
1623-
while (pg_isblank(*cursor))
1632+
while (is_ident_whitespace(*cursor))
16241633
cursor++;/* skip blanks */
16251634
if (strcmp(response_type,"USERID")!=0)
16261635
return false;
@@ -1643,7 +1652,7 @@ interpret_ident_response(const char *ident_response,
16431652
else
16441653
{
16451654
cursor++;/* Go over colon */
1646-
while (pg_isblank(*cursor))
1655+
while (is_ident_whitespace(*cursor))
16471656
cursor++;/* skip blanks */
16481657
/* Rest of line is user name. Copy it over. */
16491658
i=0;

‎src/backend/libpq/hba.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,11 @@ static intregexec_auth_token(const char *match, AuthToken *token,
138138
staticvoidtokenize_error_callback(void*arg);
139139

140140

141-
/*
142-
* isblank() exists in the ISO C99 spec, but it's not very portable yet,
143-
* so provide our own version.
144-
*/
145-
bool
141+
staticbool
146142
pg_isblank(constcharc)
147143
{
148-
returnc==' '||c=='\t'||c=='\r';
144+
/* don't accept non-ASCII data */
145+
return (!IS_HIGHBIT_SET(c)&&isblank(c));
149146
}
150147

151148

‎src/include/libpq/hba.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ extern intcheck_usermap(const char *usermap_name,
181181
boolcase_insensitive);
182182
externHbaLine*parse_hba_line(TokenizedAuthLine*tok_line,intelevel);
183183
externIdentLine*parse_ident_line(TokenizedAuthLine*tok_line,intelevel);
184-
externboolpg_isblank(constcharc);
185184
externFILE*open_auth_file(constchar*filename,intelevel,intdepth,
186185
char**err_msg);
187186
externvoidfree_auth_file(FILE*file,intdepth);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp