1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Add validation for WAL segment size in pg_control.

This serves as an additional sanity check to be sure the pg_control format is as expected. The field is useful for being near the end and containing a limited number of discrete values.
This commit is contained in:
David Steele
2024-03-10 16:17:50 +13:00
parent 63541b2273
commit 960b43589d
4 changed files with 54 additions and 1 deletions

View File

@ -180,6 +180,14 @@ pgWalSegmentSizeCheck(unsigned int pgVersion, unsigned int walSegmentSize)
PG_WAL_SEGMENT_SIZE_DEFAULT);
}
// Check that the WAL segment size is valid
if (!IsValidWalSegSize(walSegmentSize))
{
THROW_FMT(
FormatError, "wal segment size is %u but must be a power of two between %d and %d inclusive", walSegmentSize,
WalSegMinSize, WalSegMaxSize);
}
FUNCTION_TEST_RETURN_VOID();
}

View File

@ -244,4 +244,22 @@ Types from src/include/access/transam.h
*/
#define FirstNormalObjectId 16384
/***********************************************************************************************************************************
Types from src/include/access/xlog_internal.h
***********************************************************************************************************************************/
// WalSegMinSize/WalSegMinSize macros
// ---------------------------------------------------------------------------------------------------------------------------------
/* wal_segment_size can range from 1MB to 1GB */
#define WalSegMinSize 1024 * 1024
#define WalSegMaxSize 1024 * 1024 * 1024
// IsPowerOf2/IsValidWalSegSize macros
// ---------------------------------------------------------------------------------------------------------------------------------
/* check that the given size is a valid wal_segment_size */
#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
#define IsValidWalSegSize(size) \
(IsPowerOf2(size) && \
((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
#endif