Skip to content

Commit a33661b

Browse files
Fix crash in exec_internal_grant_on_function when logical schema is null (#4660) (#4674)
When creating functions in schemas created from PostgreSQL endpoint, the logical schema name is null, causing a crash in exec_internal_grant_on_function at CStringGetTextDatum(logicalschema). Fixed an issue where the system would crash when attempting to grant permissions on functions created in PostgreSQL-endpoint schemas by adding a null check for logicalschema before calling CStringGetTextDatum. Task: BABEL-6390 Signed-off-by: Harsh Lunagariya <lunharsh@amazon.com>
1 parent 228133f commit a33661b

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

contrib/babelfishpg_tsql/src/catalog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ get_logical_schema_name(const char *physical_schema_name, bool missingOk)
644644
if (!missingOk)
645645
ereport(ERROR,
646646
(errcode(ERRCODE_INTERNAL_ERROR),
647-
errmsg("Could find logical schema name for: \"%s\"", physical_schema_name)));
647+
errmsg("Could not find logical schema name for: \"%s\"", physical_schema_name)));
648648
return NULL;
649649
}
650650
datum = SysCacheGetAttr(SYSNAMESPACENAME, tuple, Anum_namespace_ext_orig_name, &isnull);
@@ -4460,7 +4460,7 @@ exec_internal_grant_on_function(Oid objectId)
44604460
object_name = NameStr(procedureStruct->proname);
44614461
phy_sch_oid = procedureStruct->pronamespace;
44624462
schema = get_namespace_name(phy_sch_oid);
4463-
logicalschema = get_logical_schema_name(schema, true);
4463+
logicalschema = get_logical_schema_name(schema, false);
44644464
object_type = procedureStruct->prokind;
44654465

44664466
/* Fetch the relation */

test/JDBC/expected/TestInteropProcedures.out

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,22 @@ GO
251251
-- psql currentSchema=master_dbo,public
252252
DROP PROCEDURE psql_interop_proc
253253
GO
254+
255+
-- psql
256+
CREATE SCHEMA master_s6390;
257+
GO
258+
259+
GRANT ALL ON SCHEMA master_s6390 TO PUBLIC ;
260+
GO
261+
262+
-- tsql
263+
CREATE FUNCTION s6390.f1() RETURNS INT AS BEGIN return 1 END;
264+
GO
265+
~~ERROR (Code: 33557097)~~
266+
267+
~~ERROR (Message: Could not find logical schema name for: "master_s6390")~~
268+
269+
270+
-- psql
271+
DROP SCHEMA master_s6390;
272+
GO

test/JDBC/expected/db_securityadmin-vu-verify.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,28 +980,28 @@ GRANT SELECT ON sys.database_principals TO babel_5135_u1;
980980
GO
981981
~~ERROR (Code: 33557097)~~
982982

983-
~~ERROR (Message: Could find logical schema name for: "sys")~~
983+
~~ERROR (Message: Could not find logical schema name for: "sys")~~
984984

985985

986986
REVOKE SELECT ON sys.database_principals FROM babel_5135_u1;
987987
GO
988988
~~ERROR (Code: 33557097)~~
989989

990-
~~ERROR (Message: Could find logical schema name for: "sys")~~
990+
~~ERROR (Message: Could not find logical schema name for: "sys")~~
991991

992992

993993
GRANT SELECT ON pg_catalog.pg_namespace TO babel_5135_u1;
994994
GO
995995
~~ERROR (Code: 33557097)~~
996996

997-
~~ERROR (Message: Could find logical schema name for: "pg_catalog")~~
997+
~~ERROR (Message: Could not find logical schema name for: "pg_catalog")~~
998998

999999

10001000
REVOKE SELECT ON pg_catalog.pg_namespace FROM babel_5135_u1;
10011001
GO
10021002
~~ERROR (Code: 33557097)~~
10031003

1004-
~~ERROR (Message: Could find logical schema name for: "pg_catalog")~~
1004+
~~ERROR (Message: Could not find logical schema name for: "pg_catalog")~~
10051005

10061006

10071007
REVOKE SELECT ON babel_5135_db1.dbo.babel_5135_show_role_mem TO babel_5135_u1;

test/JDBC/input/interoperability/TestInteropProcedures.mix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,18 @@ GO
192192
-- psql currentSchema=master_dbo,public
193193
DROP PROCEDURE psql_interop_proc
194194
GO
195+
196+
-- psql
197+
CREATE SCHEMA master_s6390;
198+
GO
199+
200+
GRANT ALL ON SCHEMA master_s6390 TO PUBLIC ;
201+
GO
202+
203+
-- tsql
204+
CREATE FUNCTION s6390.f1() RETURNS INT AS BEGIN return 1 END;
205+
GO
206+
207+
-- psql
208+
DROP SCHEMA master_s6390;
209+
GO

0 commit comments

Comments
 (0)