Skip to content

Commit 1705902

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 0d4a2f8 commit 1705902

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
@@ -696,28 +696,32 @@ other .
696696
return IDENT;
697697
}
698698
<xui>{xuistop1} {
699-
char *ident;
699+
char *ident;
700+
int identlen;
700701

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

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

0 commit comments

Comments
 (0)