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

Commit9ae2661

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 parentf61bd73 commit9ae2661

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
@@ -770,7 +770,7 @@ parse_ident(PG_FUNCTION_ARGS)
770770
nextp=qualname_str;
771771

772772
/* skip leading whitespace */
773-
while (isspace((unsignedchar)*nextp))
773+
while (scanner_isspace(*nextp))
774774
nextp++;
775775

776776
for (;;)
@@ -858,14 +858,14 @@ parse_ident(PG_FUNCTION_ARGS)
858858
text_to_cstring(qualname))));
859859
}
860860

861-
while (isspace((unsignedchar)*nextp))
861+
while (scanner_isspace(*nextp))
862862
nextp++;
863863

864864
if (*nextp=='.')
865865
{
866866
after_dot= true;
867867
nextp++;
868-
while (isspace((unsignedchar)*nextp))
868+
while (scanner_isspace(*nextp))
869869
nextp++;
870870
}
871871
elseif (*nextp=='\0')

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include"lib/stringinfo.h"
3333
#include"miscadmin.h"
3434
#include"parser/parse_type.h"
35+
#include"parser/scansup.h"
3536
#include"utils/builtins.h"
3637
#include"utils/lsyscache.h"
3738
#include"utils/syscache.h"
@@ -1769,7 +1770,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
17691770
ptr2=ptr+strlen(ptr);
17701771
while (--ptr2>ptr)
17711772
{
1772-
if (!isspace((unsignedchar)*ptr2))
1773+
if (!scanner_isspace(*ptr2))
17731774
break;
17741775
}
17751776
if (*ptr2!=')')
@@ -1786,7 +1787,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
17861787
for (;;)
17871788
{
17881789
/* allow leading whitespace */
1789-
while (isspace((unsignedchar)*ptr))
1790+
while (scanner_isspace(*ptr))
17901791
ptr++;
17911792
if (*ptr=='\0')
17921793
{
@@ -1842,7 +1843,7 @@ parseNameAndArgTypes(const char *string, bool allowNone, List **names,
18421843
/* Lop off trailing whitespace */
18431844
while (--ptr2 >=typename)
18441845
{
1845-
if (!isspace((unsignedchar)*ptr2))
1846+
if (!scanner_isspace(*ptr2))
18461847
break;
18471848
*ptr2='\0';
18481849
}

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

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

32533253
*namelist=NIL;
32543254

3255-
while (isspace((unsignedchar)*nextp))
3255+
while (scanner_isspace(*nextp))
32563256
nextp++;/* skip leading whitespace */
32573257

32583258
if (*nextp=='\0')
@@ -3290,7 +3290,7 @@ SplitIdentifierString(char *rawstring, char separator,
32903290

32913291
curname=nextp;
32923292
while (*nextp&&*nextp!=separator&&
3293-
!isspace((unsignedchar)*nextp))
3293+
!scanner_isspace(*nextp))
32943294
nextp++;
32953295
endp=nextp;
32963296
if (curname==nextp)
@@ -3312,13 +3312,13 @@ SplitIdentifierString(char *rawstring, char separator,
33123312
pfree(downname);
33133313
}
33143314

3315-
while (isspace((unsignedchar)*nextp))
3315+
while (scanner_isspace(*nextp))
33163316
nextp++;/* skip trailing whitespace */
33173317

33183318
if (*nextp==separator)
33193319
{
33203320
nextp++;
3321-
while (isspace((unsignedchar)*nextp))
3321+
while (scanner_isspace(*nextp))
33223322
nextp++;/* skip leading whitespace for next */
33233323
/* we expect another name, so done remains false */
33243324
}
@@ -3377,7 +3377,7 @@ SplitDirectoriesString(char *rawstring, char separator,
33773377

33783378
*namelist=NIL;
33793379

3380-
while (isspace((unsignedchar)*nextp))
3380+
while (scanner_isspace(*nextp))
33813381
nextp++;/* skip leading whitespace */
33823382

33833383
if (*nextp=='\0')
@@ -3414,21 +3414,21 @@ SplitDirectoriesString(char *rawstring, char separator,
34143414
while (*nextp&&*nextp!=separator)
34153415
{
34163416
/* trailing whitespace should not be included in name */
3417-
if (!isspace((unsignedchar)*nextp))
3417+
if (!scanner_isspace(*nextp))
34183418
endp=nextp+1;
34193419
nextp++;
34203420
}
34213421
if (curname==endp)
34223422
return false;/* empty unquoted name not allowed */
34233423
}
34243424

3425-
while (isspace((unsignedchar)*nextp))
3425+
while (scanner_isspace(*nextp))
34263426
nextp++;/* skip trailing whitespace */
34273427

34283428
if (*nextp==separator)
34293429
{
34303430
nextp++;
3431-
while (isspace((unsignedchar)*nextp))
3431+
while (scanner_isspace(*nextp))
34323432
nextp++;/* skip leading whitespace for next */
34333433
/* we expect another name, so done remains false */
34343434
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp