Skip to content

Commit 425013c

Browse files
committed
fix: evtrigs use existing version function as noop
Previous fix could override an existing function.
1 parent e97feab commit 425013c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/event_triggers.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "pg_prelude.h"
22
#include "event_triggers.h"
33

4-
PG_FUNCTION_INFO_V1(noop);
5-
Datum noop(__attribute__ ((unused)) PG_FUNCTION_ARGS) { PG_RETURN_VOID();}
4+
// this is the underlying function of `select version();`
5+
extern Datum pgsql_version(PG_FUNCTION_ARGS);
66

77
void
88
force_noop(FmgrInfo *finfo)
99
{
10-
finfo->fn_addr = (PGFunction) noop;
11-
finfo->fn_oid = 38; /* put the int2in oid which is sure to exist, this avoids cache lookup errors. See https://github.com/supabase/supautils/pull/129*/
12-
finfo->fn_nargs = 0; /* no arguments for noop */
10+
finfo->fn_addr = (PGFunction) pgsql_version;
11+
finfo->fn_oid = 89; /* this is the oid of pgsql_version function, it's stable and keeps being the same on latest pg version */
12+
finfo->fn_nargs = 0; /* no arguments for version() */
1313
finfo->fn_strict = false;
1414
finfo->fn_retset = false;
1515
finfo->fn_stats = 0; /* no stats collection */

src/supautils.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ static void supautils_fmgr_hook(FmgrHookEventType event, FmgrInfo *flinfo, Datum
101101
const char *current_role_name = GetUserNameFromId(GetUserId(), false);
102102
if (superuser() || is_reserved_role(current_role_name, false)) {
103103
bool function_is_owned_by_super = superuser_arg(get_function_owner((func_owner_search){ .as = FO_SEARCH_FINFO, .val.finfo = flinfo }));
104-
if (!function_is_owned_by_super)
105-
// we can't skip execution directly inside the fmgr_hook (although we can abort it with ereport)
106-
// so instead we use the workaround of changing the event trigger function to a noop function
107-
force_noop(flinfo);
104+
if (!function_is_owned_by_super){
105+
// we can't skip execution directly inside the fmgr_hook (although we can abort it with ereport)
106+
// so instead we use the workaround of changing the event trigger function to a noop function
107+
force_noop(flinfo);
108+
}
108109
}
109110

110111
if (next_fmgr_hook)

0 commit comments

Comments
 (0)