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

Commit8527132

Browse files
committed
Tighten checks for whitespace in functions that parse identifiers etc.
This patch replaces isspace() calls with scanner_isspace() in functionsthat are likely to be presented with non-ASCII input. isspace() hasthe small advantage that it will correctly recognize no-break spacein single-byte encodings (such as LATIN1); but it cannot work successfullyfor any multibyte character, and depending on platform it might returnfalse positive results for some fragments of multibyte characters. That'sdisastrous for functions that are trying to discard whitespace betweenvalid strings, as noted in bug #14662 from Justin Muise. Even treatingno-break space as whitespace is pretty questionable for the usages touchedhere, because the core scanner would think it is an identifier character.Affected functions are parse_ident(), parseNameAndArgTypes (underlyingregprocedurein() and siblings), SplitIdentifierString (used for parsingGUCs and options that are qualified names or lists of names), andSplitDirectoriesString (used for parsing GUCs that are lists ofdirectories).All the functions adjusted here are parsing SQL identifiers and similarconstructs, so it's reasonable to insist that their definition ofwhitespace match the core scanner. So we can hope that this won't causemany backwards-compatibility problems. I've left alone isspace() callsin places that aren't really expecting any non-ASCII input characters,such as float8in().Back-patch to all supported branches.Discussion:https://postgr.es/m/10129.1495302480@sss.pgh.pa.us
1 parentd8ba357 commit8527132

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

‎src/backend/utils/adt/misc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ parse_ident(PG_FUNCTION_ARGS)
775775
nextp=qualname_str;
776776

777777
/* skip leading whitespace */
778-
while (isspace((unsignedchar)*nextp))
778+
while (scanner_isspace(*nextp))
779779
nextp++;
780780

781781
for (;;)
@@ -863,14 +863,14 @@ parse_ident(PG_FUNCTION_ARGS)
863863
text_to_cstring(qualname))));
864864
}
865865

866-
while (isspace((unsignedchar)*nextp))
866+
while (scanner_isspace(*nextp))
867867
nextp++;
868868

869869
if (*nextp=='.')
870870
{
871871
after_dot= true;
872872
nextp++;
873-
while (isspace((unsignedchar)*nextp))
873+
while (scanner_isspace(*nextp))
874874
nextp++;
875875
}
876876
elseif (*nextp=='\0')

‎src/backend/utils/adt/regproc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include"lib/stringinfo.h"
3636
#include"miscadmin.h"
3737
#include"parser/parse_type.h"
38+
#include"parser/scansup.h"
3839
#include"utils/builtins.h"
3940
#include"utils/fmgroids.h"
4041
#include"utils/lsyscache.h"
@@ -1911,7 +1912,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
19111912
ptr2=ptr+strlen(ptr);
19121913
while (--ptr2>ptr)
19131914
{
1914-
if (!isspace((unsignedchar)*ptr2))
1915+
if (!scanner_isspace(*ptr2))
19151916
break;
19161917
}
19171918
if (*ptr2!=')')
@@ -1928,7 +1929,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
19281929
for (;;)
19291930
{
19301931
/* allow leading whitespace */
1931-
while (isspace((unsignedchar)*ptr))
1932+
while (scanner_isspace(*ptr))
19321933
ptr++;
19331934
if (*ptr=='\0')
19341935
{
@@ -1984,7 +1985,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
19841985
/* Lop off trailing whitespace */
19851986
while (--ptr2 >=typename)
19861987
{
1987-
if (!isspace((unsignedchar)*ptr2))
1988+
if (!scanner_isspace(*ptr2))
19881989
break;
19891990
*ptr2='\0';
19901991
}

‎src/backend/utils/adt/varlena.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,7 +3133,7 @@ SplitIdentifierString(char *rawstring, char separator,
31333133

31343134
*namelist=NIL;
31353135

3136-
while (isspace((unsignedchar)*nextp))
3136+
while (scanner_isspace(*nextp))
31373137
nextp++;/* skip leading whitespace */
31383138

31393139
if (*nextp=='\0')
@@ -3171,7 +3171,7 @@ SplitIdentifierString(char *rawstring, char separator,
31713171

31723172
curname=nextp;
31733173
while (*nextp&&*nextp!=separator&&
3174-
!isspace((unsignedchar)*nextp))
3174+
!scanner_isspace(*nextp))
31753175
nextp++;
31763176
endp=nextp;
31773177
if (curname==nextp)
@@ -3193,13 +3193,13 @@ SplitIdentifierString(char *rawstring, char separator,
31933193
pfree(downname);
31943194
}
31953195

3196-
while (isspace((unsignedchar)*nextp))
3196+
while (scanner_isspace(*nextp))
31973197
nextp++;/* skip trailing whitespace */
31983198

31993199
if (*nextp==separator)
32003200
{
32013201
nextp++;
3202-
while (isspace((unsignedchar)*nextp))
3202+
while (scanner_isspace(*nextp))
32033203
nextp++;/* skip leading whitespace for next */
32043204
/* we expect another name, so done remains false */
32053205
}
@@ -3258,7 +3258,7 @@ SplitDirectoriesString(char *rawstring, char separator,
32583258

32593259
*namelist=NIL;
32603260

3261-
while (isspace((unsignedchar)*nextp))
3261+
while (scanner_isspace(*nextp))
32623262
nextp++;/* skip leading whitespace */
32633263

32643264
if (*nextp=='\0')
@@ -3295,21 +3295,21 @@ SplitDirectoriesString(char *rawstring, char separator,
32953295
while (*nextp&&*nextp!=separator)
32963296
{
32973297
/* trailing whitespace should not be included in name */
3298-
if (!isspace((unsignedchar)*nextp))
3298+
if (!scanner_isspace(*nextp))
32993299
endp=nextp+1;
33003300
nextp++;
33013301
}
33023302
if (curname==endp)
33033303
return false;/* empty unquoted name not allowed */
33043304
}
33053305

3306-
while (isspace((unsignedchar)*nextp))
3306+
while (scanner_isspace(*nextp))
33073307
nextp++;/* skip trailing whitespace */
33083308

33093309
if (*nextp==separator)
33103310
{
33113311
nextp++;
3312-
while (isspace((unsignedchar)*nextp))
3312+
while (scanner_isspace(*nextp))
33133313
nextp++;/* skip leading whitespace for next */
33143314
/* we expect another name, so done remains false */
33153315
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp