You've already forked pgbackrest
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:
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user