From 77853d3c1387cd6ba42396e7ca29fae0f18ab6ac Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 5 Mar 2020 11:14:53 -0500 Subject: [PATCH] Remove invalid const in pgPageChecksum() parameter. pgPageChecksum() must modify the page header in order to calculate the checksum. The modification is temporary but make it clear that it happens by removing the const. Also make a note about our non-entirely-kosher usage of a const Buffer in the PageChecksum filter. This is safe as currently coded but at the least we need to be aware of what is going on. --- libc/xs/postgres/pageChecksum.xs | 4 ++-- src/command/backup/pageChecksum.c | 4 ++++ src/postgres/pageChecksum.c | 6 +++--- src/postgres/pageChecksum.h | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libc/xs/postgres/pageChecksum.xs b/libc/xs/postgres/pageChecksum.xs index 1ef098760..a68863ab8 100644 --- a/libc/xs/postgres/pageChecksum.xs +++ b/libc/xs/postgres/pageChecksum.xs @@ -6,14 +6,14 @@ MODULE = pgBackRest::LibC PACKAGE = pgBackRest::LibC U16 pgPageChecksum(page, blockNo) - const char *page + unsigned char *page U32 blockNo CODE: RETVAL = 0; ERROR_XS_BEGIN() { - RETVAL = pgPageChecksum((const unsigned char *)page, blockNo); + RETVAL = pgPageChecksum(page, blockNo); } ERROR_XS_END(); OUTPUT: diff --git a/src/command/backup/pageChecksum.c b/src/command/backup/pageChecksum.c index 614aa1275..8713e4a3f 100644 --- a/src/command/backup/pageChecksum.c +++ b/src/command/backup/pageChecksum.c @@ -95,6 +95,10 @@ pageChecksumProcess(THIS_VOID, const Buffer *input) { for (unsigned int pageIdx = 0; pageIdx < pageTotal; pageIdx++) { + // Get a non-const pointer which is required by pgPageChecksumTest() below. ??? This is not entirely kosher since we are + // being passed a const buffer and we should deinitely not be modifying the contents. When pgPageChecksumTest() returns + // the data should be the same, but there's no question that some munging occurs. Should we make a copy of the page + // before passing it into pgPageChecksumTest()? unsigned char *pagePtr = bufPtr(input) + (pageIdx * PG_PAGE_SIZE_DEFAULT); unsigned int pageNo = this->pageNoOffset + pageIdx; size_t pageSize = this->align || pageIdx < pageTotal - 1 ? PG_PAGE_SIZE_DEFAULT : pageRemainder; diff --git a/src/postgres/pageChecksum.c b/src/postgres/pageChecksum.c index a9c9a9f8e..07bea9b2f 100644 --- a/src/postgres/pageChecksum.c +++ b/src/postgres/pageChecksum.c @@ -101,7 +101,7 @@ do { \ } while (0) static uint32_t -pageChecksumBlock(const unsigned char *page) +pageChecksumBlock(unsigned char *page) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM_P(UCHARDATA, page); @@ -141,7 +141,7 @@ The checksum includes the block number (to detect the case where a page is someh (excluding the checksum itself), and the page data. ***********************************************************************************************************************************/ uint16_t -pgPageChecksum(const unsigned char *page, unsigned int blockNo) +pgPageChecksum(unsigned char *page, unsigned int blockNo) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM_P(UCHARDATA, page); @@ -184,7 +184,7 @@ pageChecksumTest - test if checksum is valid for a single page ***********************************************************************************************************************************/ bool pgPageChecksumTest( - const unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset) + unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM_P(UCHARDATA, page); diff --git a/src/postgres/pageChecksum.h b/src/postgres/pageChecksum.h index 24cbc4a11..dbc2d6a52 100644 --- a/src/postgres/pageChecksum.h +++ b/src/postgres/pageChecksum.h @@ -9,9 +9,9 @@ Checksum Implementation for Data Pages /*********************************************************************************************************************************** Functions ***********************************************************************************************************************************/ -uint16_t pgPageChecksum(const unsigned char *page, unsigned int blockNo); +uint16_t pgPageChecksum(unsigned char *page, unsigned int blockNo); uint64_t pgPageLsn(const unsigned char *page); bool pgPageChecksumTest( - const unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset); + unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset); #endif