Skip to content

Commit

Permalink
Fix crash issue in pre transforming column name (#2754)
Browse files Browse the repository at this point in the history
Fix the crash happen when column ref is followed by a comment without
space like : 'SELECT table1.c2--table1.REPGETTEXT('.

Previously, the column transform didn't consider '--' will directly
followed with column ref and will wrongly regard the comment part
as the column ref, thus will cause crash later in finding the column name.

This fix add the check for '--' at the end of column def in the sql string to avoid this crash.

Task: BABEL-5070
Signed-off-by: Zhibai Song <[email protected]>
  • Loading branch information
forestkeeper authored Jul 22, 2024
1 parent f2b5101 commit 42ac53c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
12 changes: 11 additions & 1 deletion contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,17 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate,
colname_start = pstate->p_sourcetext + res->location;
last_dot = colname_start;
while(*colname_start != '\0')
{
{
/*
* comment follow up with column like :
*
* 'SELECT table1.c2--table1.REPGETTEXT('
*
* will cause crash if we don't break the searching
* for the last_dot position
*/
if (*colname_start == '-' && *(colname_start+1) == '-')
break;
if(open_square_bracket == 0 && *colname_start == '"')
{
double_quotes++;
Expand Down
40 changes: 40 additions & 0 deletions test/JDBC/expected/BABEL-4484-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,43 @@ GO
varchar
~~END~~


SELECT test_babel_4484_t1.ced--table1.REPGETTEXT(
FROM test_babel_4484_t1
GO
~~START~~
varchar
~~END~~


select test_babel_4484_t1.您您--table1.a.b.c
from test_babel_4484_t1
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: column test_babel_4484_t1.您您 does not exist)~~


select test_babel_4484_t2.您您--table1.a.b.c
from test_babel_4484_t2
GO
~~START~~
varchar
~~END~~


select test_babel_4484_t1.您您 as kk--table1.a.b.c
from test_babel_4484_t1
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: column test_babel_4484_t1.您您 does not exist)~~


select test_babel_4484_t2.您您 as kk--table1.a.b.c
from test_babel_4484_t2
GO
~~START~~
varchar
~~END~~

20 changes: 20 additions & 0 deletions test/JDBC/input/BABEL-4484-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ GO

SELECT test_babel_4484_t1.ced FROM test_babel_4484_t1 INNER JOIN test_babel_4484_t2 ON test_babel_4484_t1.ABC = test_babel_4484_t2.ABC WHERE test_babel_4484_t1.ABC = 1;
GO

SELECT test_babel_4484_t1.ced--table1.REPGETTEXT(
FROM test_babel_4484_t1
GO

select test_babel_4484_t1.您您--table1.a.b.c
from test_babel_4484_t1
GO

select test_babel_4484_t2.您您--table1.a.b.c
from test_babel_4484_t2
GO

select test_babel_4484_t1.您您 as kk--table1.a.b.c
from test_babel_4484_t1
GO

select test_babel_4484_t2.您您 as kk--table1.a.b.c
from test_babel_4484_t2
GO

0 comments on commit 42ac53c

Please sign in to comment.