Skip to content

Commit c1a0d7d

Browse files
committed
Fix NULL input behaviour of pg_stat_get_replication_slot().
pg_stat_get_replication_slot() accidentally was marked as non-strict, crashing when called with NULL input. As it's already released, introduce an explicit NULL check in 14, fix the catalog in HEAD. Bumps catversion in HEAD. Discussion: https://postgr.es/m/20220326212432.s5n2maw6kugnpyxw@alap3.anarazel.de Backpatch: 14-, where replication slot stats were introduced
1 parent 6839aa7 commit c1a0d7d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2315,14 +2315,23 @@ Datum
23152315
pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
23162316
{
23172317
#define PG_STAT_GET_REPLICATION_SLOT_COLS 10
2318-
text *slotname_text = PG_GETARG_TEXT_P(0);
2318+
text *slotname_text;
23192319
NameData slotname;
23202320
TupleDesc tupdesc;
23212321
Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS];
23222322
bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS];
23232323
PgStat_StatReplSlotEntry *slotent;
23242324
PgStat_StatReplSlotEntry allzero;
23252325

2326+
/*
2327+
* Function was accidentally marked as non-strict, can't change that post
2328+
* release.
2329+
*/
2330+
if (PG_ARGISNULL(0))
2331+
PG_RETURN_NULL();
2332+
2333+
slotname_text = PG_GETARG_TEXT_P(0);
2334+
23262335
/* Initialise values and NULL flags arrays */
23272336
MemSet(values, 0, sizeof(values));
23282337
MemSet(nulls, 0, sizeof(nulls));

src/test/regress/expected/stats.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,11 @@ FROM prevstats AS pr;
201201

202202
DROP TABLE trunc_stats_test, trunc_stats_test1, trunc_stats_test2, trunc_stats_test3, trunc_stats_test4;
203203
DROP TABLE prevstats;
204+
-- ensure that stats accessors handle NULL input correctly
205+
SELECT pg_stat_get_replication_slot(NULL);
206+
pg_stat_get_replication_slot
207+
------------------------------
208+
209+
(1 row)
210+
204211
-- End of Stats Test

src/test/regress/sql/stats.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,10 @@ FROM prevstats AS pr;
176176

177177
DROP TABLE trunc_stats_test, trunc_stats_test1, trunc_stats_test2, trunc_stats_test3, trunc_stats_test4;
178178
DROP TABLE prevstats;
179+
180+
181+
-- ensure that stats accessors handle NULL input correctly
182+
SELECT pg_stat_get_replication_slot(NULL);
183+
184+
179185
-- End of Stats Test

0 commit comments

Comments
 (0)