Skip to content

Commit

Permalink
NULL check for crasing test cases
Browse files Browse the repository at this point in the history
Signed-off-by: P Aswini Kumar <[email protected]>
  • Loading branch information
P Aswini Kumar committed Sep 18, 2024
1 parent c87ba29 commit 79bd0ff
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 34 deletions.
20 changes: 13 additions & 7 deletions contrib/babelfishpg_tsql/runtime/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,8 @@ schema_id(PG_FUNCTION_ARGS)
if (!user)
{
pfree(db_name);
pfree(guest_role_name);
if(guest_role_name)
pfree(guest_role_name);
PG_RETURN_NULL();
}
else if ((guest_role_name && strcmp(user, guest_role_name) == 0))
Expand All @@ -1323,7 +1324,8 @@ schema_id(PG_FUNCTION_ARGS)
physical_name = get_physical_schema_name(db_name, name);
}
pfree(db_name);
pfree(guest_role_name);
if(guest_role_name)
pfree(guest_role_name);
}
else
{
Expand Down Expand Up @@ -2224,14 +2226,15 @@ object_id(PG_FUNCTION_ARGS)
* name
*/
const char *user = get_user_for_database(db_name);
char *guest_role_name = get_guest_role_name(db_name);
char *guest_role_name = get_guest_role_name(db_name);

if (!user)
{
pfree(db_name);
pfree(schema_name);
pfree(object_name);
pfree(guest_role_name);
if(guest_role_name)
pfree(guest_role_name);
if (object_type)
pfree(object_type);
PG_RETURN_NULL();
Expand All @@ -2246,7 +2249,8 @@ object_id(PG_FUNCTION_ARGS)
schema_name = get_authid_user_ext_schema_name((const char *) db_name, user);
physical_schema_name = get_physical_schema_name(db_name, schema_name);
}
pfree(guest_role_name);
if(guest_role_name)
pfree(guest_role_name);
}
else
{
Expand Down Expand Up @@ -2687,7 +2691,8 @@ type_id(PG_FUNCTION_ARGS)
pfree(db_name);
pfree(schema_name);
pfree(object_name);
pfree(guest_role_name);
if(guest_role_name)
pfree(guest_role_name);
PG_RETURN_NULL();
}
else if ((guest_role_name && strcmp(user, guest_role_name) == 0))
Expand All @@ -2700,7 +2705,8 @@ type_id(PG_FUNCTION_ARGS)
schema_name = get_authid_user_ext_schema_name((const char *) db_name, user);
physical_schema_name = get_physical_schema_name(db_name, schema_name);
}
pfree(guest_role_name);
if(guest_role_name)
pfree(guest_role_name);
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions contrib/babelfishpg_tsql/src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -3121,7 +3121,9 @@ guest_role_exists_for_db(const char *dbname)

systable_endscan(scan);
table_close(bbf_authid_user_ext_rel, RowExclusiveLock);
pfree(guest_role);

if(guest_role)
pfree(guest_role);

return role_exists;
}
Expand Down Expand Up @@ -3218,7 +3220,8 @@ create_guest_role_for_db(const char *dbname)
SetConfigOption("createrole_self_grant", old_createrole_self_grant, PGC_USERSET, PGC_S_OVERRIDE);
SetUserIdAndSecContext(save_userid, save_sec_context);
set_cur_db(old_dbid, old_dbname);
pfree(guest);
if(guest)
pfree(guest);
}
PG_END_TRY();
}
Expand Down
18 changes: 12 additions & 6 deletions contrib/babelfishpg_tsql/src/dbcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,10 @@ create_bbf_db_internal(ParseState *pstate, const char *dbname, List *options, co
SetConfigOption("createrole_self_grant", old_createrole_self_grant, PGC_USERSET, PGC_S_OVERRIDE);
SetUserIdAndSecContext(save_userid, save_sec_context);
set_cur_db(old_dbid, old_dbname);
pfree(dbo_scm);
pfree(guest_scm);
if(dbo_scm)
pfree(dbo_scm);
if(guest_scm)
pfree(guest_scm);
}
PG_END_TRY();
}
Expand Down Expand Up @@ -833,10 +835,14 @@ drop_bbf_db(const char *dbname, bool missing_ok, bool force_drop)
}
PG_END_TRY();

pfree(schema_name);
pfree(db_owner_role);
pfree(dbo_role);
pfree(guest_schema_name);
if(schema_name)
pfree(schema_name);
if(db_owner_role)
pfree(db_owner_role);
if(dbo_role)
pfree(dbo_role);
if(guest_schema_name)
pfree(guest_schema_name);

/* Set current user back to previous user */
bbf_set_current_user(prev_current_user);
Expand Down
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4949,9 +4949,9 @@ get_local_schema_for_bbf_functions(Oid proc_nsp_oid)
quote_identifier(func_dbo_schema));

ReleaseSysCache(tuple);
if(func_dbo_schema)
pfree(func_dbo_schema);
}

pfree(func_dbo_schema);

return new_search_path;
}
Expand Down
10 changes: 6 additions & 4 deletions contrib/babelfishpg_tsql/src/pl_exec-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3347,8 +3347,10 @@ void exec_stmt_dbcc_checkident(PLtsql_stmt_dbcc *stmt)
}
}
pfree(db_name);
pfree(guest_role_name);
pfree(dbo_role_name);
if(guest_role_name)
pfree(guest_role_name);
if(dbo_role_name)
pfree(dbo_role_name);

/*
* get schema oid from physical schema name, it will return InvalidOid if
Expand Down Expand Up @@ -3402,8 +3404,8 @@ void exec_stmt_dbcc_checkident(PLtsql_stmt_dbcc *stmt)
errmsg("'%s.%s' does not contain an identity column.",
nsp_name, dbcc_stmt.table_name)));
}

pfree(nsp_name);
if(nsp_name)
pfree(nsp_name);

PG_TRY();
{
Expand Down
6 changes: 4 additions & 2 deletions contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3283,7 +3283,8 @@ bbf_ProcessUtility(PlannedStmt *pstmt,
set_session_properties(db_name);
pfree(cur_user);
pfree(db_name);
pfree(dbo_name);
if(dbo_name)
pfree(dbo_name);

return;
}
Expand Down Expand Up @@ -3408,7 +3409,8 @@ bbf_ProcessUtility(PlannedStmt *pstmt,
}

pfree(rolspec->rolename);
pfree(db_owner_name);
if(db_owner_name)
pfree(db_owner_name);
rolspec->rolename = user_name;
}
}
Expand Down
3 changes: 2 additions & 1 deletion contrib/babelfishpg_tsql/src/procedures.c
Original file line number Diff line number Diff line change
Expand Up @@ -3379,7 +3379,8 @@ sp_babelfish_volatility(PG_FUNCTION_ARGS)
physical_schema_name = get_physical_schema_name(db_name, logical_schema_name);
pfree(logical_schema_name);
}
pfree(guest_role_name);
if(guest_role_name)
pfree(guest_role_name);
}
else
{
Expand Down
21 changes: 14 additions & 7 deletions contrib/babelfishpg_tsql/src/rolecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant)
CommandCounterIncrement();

pfree(query.data);
pfree(dbo_role_name);
if(dbo_role_name)
pfree(dbo_role_name);
}

static List *
Expand Down Expand Up @@ -1990,20 +1991,26 @@ is_rolemember(PG_FUNCTION_ARGS)
dbo_role_oid = get_role_oid(dbo_role_name, false);
if ((principal_oid == db_owner_oid) || (principal_oid == dbo_role_oid))
{
pfree(db_owner_name);
pfree(dbo_role_name);
if(db_owner_name)
pfree(db_owner_name);
if(dbo_role_name)
pfree(dbo_role_name);
PG_RETURN_INT32(0);
}
else if (is_member_of_role_nosuper(principal_oid, role_oid))
{
pfree(db_owner_name);
pfree(dbo_role_name);
if(db_owner_name)
pfree(db_owner_name);
if(dbo_role_name)
pfree(dbo_role_name);
PG_RETURN_INT32(1);
}
else
{
pfree(db_owner_name);
pfree(dbo_role_name);
if(db_owner_name)
pfree(db_owner_name);
if(dbo_role_name)
pfree(dbo_role_name);
PG_RETURN_INT32(0);
}
}
Expand Down
9 changes: 6 additions & 3 deletions contrib/babelfishpg_tsql/src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ set_search_path_for_user_schema(const char *db_name, const char *user)
PGC_SUSET,
PGC_S_DATABASE_USER);

pfree(dbo_role_name);
pfree(guest_role_name);
pfree(physical_schema);
if(dbo_role_name)
pfree(dbo_role_name);
if(guest_role_name)
pfree(guest_role_name);
if(physical_schema)
pfree(physical_schema);
}

/*
Expand Down

0 comments on commit 79bd0ff

Please sign in to comment.