| From: | Sami Imseih <samimseih(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | add validations for required callbacks during pgstat_register_kind() |
| Date: | 2026-07-02 21:48:25 |
| Message-ID: | CAA5RZ0uNoe=xT7QsU1K0mMRg-QAwPtupPWZ2J3weM2PjVL2tiA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
While looking at pgstat custom kind registration, I realized there are
a few callbacks that are mandatory and not setting them will
result in NULL pointer dereferences.
For fixed-amount kinds, init_shmem_cb, reset_all_cb, and snapshot_cb
are called unconditionally. A missing callback crashes the server at
startup or during recovery.
For variable-numbered kinds, flush_pending_cb is called unconditionally
when flushing pending entries. If pending_size is set but
flush_pending_cb is NULL, the server crashes when that callback is run.
Adding validations will make it clear these are required.
Also, there is an assert for snapshot_cb before it's called in
pgstat_build_snapshot_fixed(), but we don't have the same assert for
init_shmem_cb and reset_all_cb. The attached also adds these asserts.
These asserts are needed for built-in stats that don't go through
pgstat_register_kind()
--
Sami Imseih
Amazon Web Services (AWS)
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Add-validations-for-required-callbacks-during-pgs.patch | application/octet-stream | 3.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Masahiko Sawada | 2026-07-02 21:49:56 | Re: Report bytes and transactions actually sent downtream |
| Previous Message | Paul A Jungwirth | 2026-07-02 21:39:57 | Re: SQL:2011 Application Time Update & Delete |