8000 Fix length checking for Unicode identifiers containing escapes (U&"..… · xiaom/postgres@8439ee4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8439ee4

Browse files
committed
Fix length checking for Unicode identifiers containing escapes (U&"...").
We used the length of the input string, not the de-escaped string, as the trigger for NAMEDATALEN truncation. AFAICS this would only result in sometimes printing a phony truncation warning; but it's just luck that there was no worse problem, since we were violating the API spec for truncate_identifier(). Per bug #9204 from Joshua Yanovski. This has been wrong since the Unicode-identifier support was added, so back-patch to all supported branches.
1 parent 22fce59 commit 8439ee4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/parser/scan.l

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -697,28 +697,32 @@ other .
697697
return IDENT;
698698
}
699699
<xui>{xuistop1} {
700-
char *ident;
700+
char *ident;
701+
int identlen;
701702

702703
BEGIN(INITIAL);
703704
if (yyextra->literallen == 0)
704705
yyerror("zero-length delimited identifier");
705706
ident = litbuf_udeescape('\\', yyscanner);
706-
if (yyextra->literallen >= NAMEDATALEN)
707-
truncate_identifier(ident, yyextra->literallen, true);
707+
identlen = strlen(ident);
708+
if (identlen >= NAMEDATALEN)
709+
truncate_identifier(ident, identlen, true);
708710
yylval->str = ident;
709711
/* throw back all but the quote */
710712
yyless(1);
711713
return IDENT;
712714
}
713715
<xui>{xuistop2} {
714-
char *ident;
716+
char *ident;
717+
int identlen;
715718

716719
BEGIN(INITIAL);
717720
if (yyextra->literallen == 0)
718721
yyerror("zero-length delimited identifier");
719722
ident = litbuf_udeescape(yytext[yyleng - 2], yyscanner);
720-
if (yyextra->literallen >= NAMEDATALEN)
721-
truncate_identifier(ident, yyextra->literallen, true);
723+
identlen = strlen(ident);
724+
if (identlen >= NAMEDATALEN)
725+
truncate_identifier(ident, identlen, true);
722726
yylval->str = ident;
723727
return IDENT;
724728
}

0 commit comments

Comments
 (0)
0