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: v1-0001-Add-validations-for-required-callbacks-during-pgs.patch
Description: Binary data

Reply via email to