diff --git a/.travis.yml b/.travis.yml index 2c63eff..f68e8de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ dist: jammy language: c env: -- PG_MAJOR=18 SNAPSHOT=1 +- PG_MAJOR=19 SNAPSHOT=1 +- PG_MAJOR=18 - PG_MAJOR=17 - PG_MAJOR=16 - PG_MAJOR=15 diff --git a/pg_wait_sampling.c b/pg_wait_sampling.c index a35fb94..7e8abb9 100644 --- a/pg_wait_sampling.c +++ b/pg_wait_sampling.c @@ -75,14 +75,12 @@ static PlannedStmt *pgws_planner_hook(Query *parse, #if PG_VERSION_NUM >= 130000 const char *query_string, #endif - int cursorOptions, ParamListInfo boundParams); -static -#if PG_VERSION_NUM >= 180000 -bool -#else -void + int cursorOptions, ParamListInfo boundParams +#if PG_VERSION_NUM >= 190000 + , ExplainState *es #endif -pgws_ExecutorStart(QueryDesc *queryDesc, int eflags); + ); +static void pgws_ExecutorStart(QueryDesc *queryDesc, int eflags); static void pgws_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count @@ -655,6 +653,10 @@ receive_array(SHMRequest request, Size item_size, Size *count) pgws_collector_hdr->request = request; LockRelease(&collectorTag, ExclusiveLock, false); + /* + * Check that the collector was started to avoid NULL + * pointer dereference. + */ if (!pgws_collector_hdr->latch) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("pg_wait_sampling collector wasn't started"))); @@ -825,6 +827,14 @@ pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS) pgws_collector_hdr->request = PROFILE_RESET; LockRelease(&collectorTag, ExclusiveLock, false); + /* + * Check that the collector was started to avoid NULL + * pointer dereference. + */ + if (!pgws_collector_hdr->latch) + ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("pg_wait_sampling collector wasn't started"))); + SetLatch(pgws_collector_hdr->latch); LockRelease(&queueTag, ExclusiveLock, false); @@ -931,7 +941,11 @@ pgws_planner_hook(Query *parse, const char *query_string, #endif int cursorOptions, - ParamListInfo boundParams) + ParamListInfo boundParams +#if PG_VERSION_NUM >= 190000 + , ExplainState *es +#endif + ) { PlannedStmt *result; int i = MyProc - ProcGlobal->allProcs; @@ -952,13 +966,21 @@ pgws_planner_hook(Query *parse, #if PG_VERSION_NUM >= 130000 query_string, #endif - cursorOptions, boundParams); + cursorOptions, boundParams +#if PG_VERSION_NUM >= 190000 + , es +#endif + ); else result = standard_planner(parse, #if PG_VERSION_NUM >= 130000 query_string, #endif - cursorOptions, boundParams); + cursorOptions, boundParams +#if PG_VERSION_NUM >= 190000 + , es +#endif + ); nesting_level--; if (nesting_level == 0) pgws_proc_queryids[i] = UINT64CONST(0); @@ -982,12 +1004,7 @@ pgws_planner_hook(Query *parse, /* * ExecutorStart hook: save queryId for collector */ -static -#if PG_VERSION_NUM >= 180000 -bool -#else -void -#endif +static void pgws_ExecutorStart(QueryDesc *queryDesc, int eflags) { int i = MyProc - ProcGlobal->allProcs; @@ -995,9 +1012,9 @@ pgws_ExecutorStart(QueryDesc *queryDesc, int eflags) if (pgws_enabled(nesting_level)) pgws_proc_queryids[i] = queryDesc->plannedstmt->queryId; if (prev_ExecutorStart) - return prev_ExecutorStart(queryDesc, eflags); + prev_ExecutorStart(queryDesc, eflags); else - return standard_ExecutorStart(queryDesc, eflags); + standard_ExecutorStart(queryDesc, eflags); } static void diff --git a/run-tests.sh b/run-tests.sh index f3f1bba..f42e999 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -6,6 +6,7 @@ export PGDATA=/var/lib/postgresql/$PG_MAJOR/test export COPT=-Werror export USE_PGXS=1 +sudo mkdir -p /var/lib/postgresql/$PG_MAJOR sudo chmod 1777 /var/lib/postgresql/$PG_MAJOR sudo chmod 1777 /var/run/postgresql