Commit 7b7e5922 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-24156 trx_undo_left() fails to prevent overflow

trx_undo_left(): Return 0 in case of an overflow, instead of
returning a negative number interpreted as a large positive number.
Also, add debug assertions to check that the pointer is within
the page area. This should allow us to catch bugs like
MDEV-24096 easier in the future.
parent bd528b0c
...@@ -128,20 +128,18 @@ trx_undo_parse_add_undo_rec( ...@@ -128,20 +128,18 @@ trx_undo_parse_add_undo_rec(
return(ptr + len); return(ptr + len);
} }
/**********************************************************************//** /** Calculate the free space left for extending an undo log record.
Calculates the free space left for extending an undo log record. @param page undo log page
@param ptr current end of the undo page
@return bytes left */ @return bytes left */
UNIV_INLINE static ulint trx_undo_left(const page_t *page, const byte *ptr)
ulint
trx_undo_left(
/*==========*/
const page_t* page, /*!< in: undo log page */
const byte* ptr) /*!< in: pointer to page */
{ {
/* The '- 10' is a safety margin, in case we have some small ut_ad(ptr >= &page[TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE]);
calculation error below */ /* The 10 is supposed to be an extra safety margin (and needed for
compatibility with older versions) */
return(UNIV_PAGE_SIZE - (ptr - page) - 10 - FIL_PAGE_DATA_END); lint left= srv_page_size - (ptr - page) - (10 + FIL_PAGE_DATA_END);
ut_ad(left >= 0);
return left < 0 ? 0 : static_cast<ulint>(left);
} }
/**********************************************************************//** /**********************************************************************//**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment