Skip to content

Commit

Permalink
Add null check for func args in tsql_get_expr (babelfish-for-postgres…
Browse files Browse the repository at this point in the history
…ql#3527)

The function get_rule_expr inside of sys.tsql_get_expr crashes when the param is null. Adding null check for the input parameters.

Task: BABEL-5460

Signed-off-by: Sharath BP <[email protected]>
  • Loading branch information
sharathbp authored Feb 28, 2025
1 parent 0a03c22 commit 1676b52
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions contrib/babelfishpg_tsql/src/pltsql_ruleutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,16 @@ PG_FUNCTION_INFO_V1(tsql_get_expr);
Datum
tsql_get_expr(PG_FUNCTION_ARGS)
{
text *expr = PG_GETARG_TEXT_PP(0);
Oid relid = PG_GETARG_OID(1);
text *expr;
Oid relid;
int prettyFlags;
char *relname;


if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
PG_RETURN_NULL();

expr = PG_GETARG_TEXT_PP(0);
relid = PG_GETARG_OID(1);
prettyFlags = PRETTYFLAG_INDENT;

if (OidIsValid(relid))
Expand Down
8 changes: 8 additions & 0 deletions test/JDBC/expected/sys-computed_columns-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ text
<NULL>
~~END~~


Select sys.tsql_get_expr(null, null)
GO
~~START~~
text
<NULL>
~~END~~

3 changes: 3 additions & 0 deletions test/JDBC/input/views/sys-computed_columns-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ Select sys.tsql_get_expr('abc',123)
GO

Select sys.tsql_get_expr('abc',0)
GO

Select sys.tsql_get_expr(null, null)
GO

0 comments on commit 1676b52

Please sign in to comment.