add validations for required callbacks during pgstat_register_kind() - Mailing list pgsql-hackers

From Sami Imseih
Subject add validations for required callbacks during pgstat_register_kind()
Date
Msg-id CAA5RZ0uNoe=xT7QsU1K0mMRg-QAwPtupPWZ2J3weM2PjVL2tiA@mail.gmail.com
Whole thread
Responses Re: add validations for required callbacks during pgstat_register_kind()
List 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

pgsql-hackers by date:

Previous
From: Paul A Jungwirth
Date:
Subject: Re: SQL:2011 Application Time Update & Delete
Next
From: Masahiko Sawada
Date:
Subject: Re: Report bytes and transactions actually sent downtream