From 997639c067a8af1ae11c58d7ef74ef42dd7cab32 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Fri, 12 Nov 2021 10:58:56 -0300 Subject: [PATCH] PG-272: Fix server crash when calling pg_stat_monitor_reset(). The loop that resets the query buffers was incorrecly using MAX_BUCKETS to indicate the number of buckets to clear, which defaults to 10. If a user lowers this value the loop would access a pointer beyond the number of query buffers allocated. Fix the problem by using the correct PGSM_MAX_BUCKETS GUC as the limit to the loop. --- pg_stat_monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 41c23c8..4afee9d 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -1579,7 +1579,7 @@ pg_stat_monitor_reset(PG_FUNCTION_ARGS) LWLockAcquire(pgss->lock, LW_EXCLUSIVE); hash_entry_dealloc(-1, -1, NULL); /* Reset query buffers. */ - for (size_t i = 0; i < MAX_BUCKETS; ++i) + for (size_t i = 0; i < PGSM_MAX_BUCKETS; ++i) { *(uint64 *)pgss_qbuf[i] = 0; }