Add overflow protection for block-related data in WAL records
authorMichael Paquier <michael@paquier.xyz>
Wed, 27 Jul 2022 04:35:40 +0000 (13:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 27 Jul 2022 04:35:40 +0000 (13:35 +0900)
commitffd1b6bb6f8a2ffc929699772610c6925364dbb3
tree79d1218236c71707fc407c8c853839826cb75a48
parent70988b7b0a0bd03c59a2314d0b5bcf2135692349
Add overflow protection for block-related data in WAL records

XLogRecordBlockHeader, the header holding the information for the data
related to a block, tracks the length of the data appended to the WAL
record with data_length (uint16).  This limitation in size was not
enforced by the public routine in charge of registering the data
assembled later to form the WAL record inserted, XLogRegisterBufData().
Incorrectly used, it could lead to the generation of records with some
of its data overflowed.  This commit adds some safeguards to prevent
that for the block data, complaining immediately if attempting to add to
a record block information with a size larger than UINT16_MAX, which is
the limit implied by the internal logic.

Note that this also adjusts XLogRegisterData() and XLogRegisterBufData()
so as the length of the WAL record data given by the caller is unsigned,
matching with what gets stored in XLogRecData->len.

Extracted from a larger patch by the same author.  The original patch
includes more protections when assembling a record in full that will be
looked at separately later.

Author: Matthias van de Meent
Reviewed-by: Andres Freund, Heikki Linnakangas, Michael Paquier, David
Zhang
Discussion: https://postgr.es/m/CAEze2WgGiw+LZt+vHf8tWqB_6VxeLsMeoAuod0N=ij1q17n5pw@mail.gmail.com
src/backend/access/transam/xloginsert.c
src/include/access/xloginsert.h