Skip to content

Commit 9e6f3df

Browse files
committed
MDEV-8799: Server crashes in btr_defragment_add_index, encryption.innodb-bad-key-change5 and alike fail in buildbot
Problem was unsafe access to NULL pointer. Added additional checks to avoid access to NULL pointer.
1 parent 3a0df3c commit 9e6f3df

File tree

6 files changed

+66
-22
lines changed

6 files changed

+66
-22
lines changed

storage/innobase/btr/btr0cur.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,15 +1671,24 @@ btr_cur_pessimistic_insert(
16711671
btr_cur_get_page_zip(cursor),
16721672
thr_get_trx(thr)->id, mtr);
16731673
}
1674-
if (!page_rec_is_infimum(btr_cur_get_rec(cursor))
1675-
|| btr_page_get_prev(
1676-
buf_block_get_frame(
1677-
btr_cur_get_block(cursor)), mtr)
1678-
== FIL_NULL) {
1674+
1675+
if (!page_rec_is_infimum(btr_cur_get_rec(cursor))) {
16791676
/* split and inserted need to call
16801677
lock_update_insert() always. */
16811678
inherit = TRUE;
16821679
}
1680+
1681+
buf_block_t* block = btr_cur_get_block(cursor);
1682+
buf_frame_t* frame = NULL;
1683+
1684+
if (block) {
1685+
frame = buf_block_get_frame(block);
1686+
}
1687+
/* split and inserted need to call
1688+
lock_update_insert() always. */
1689+
if (frame && btr_page_get_prev(frame, mtr) == FIL_NULL) {
1690+
inherit = TRUE;
1691+
}
16831692
}
16841693

16851694
#ifdef BTR_CUR_ADAPT

storage/innobase/btr/btr0defragment.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ btr_defragment_add_index(
220220

221221
mtr_start(&mtr);
222222
// Load index rood page.
223-
page_t* page = btr_page_get(space, zip_size, page_no,
224-
RW_NO_LATCH, index, &mtr);
223+
buf_block_t* block = btr_block_get(space, zip_size, page_no, RW_NO_LATCH, index, &mtr);
224+
page_t* page = NULL;
225+
226+
if (block) {
227+
page = buf_block_get_frame(block);
228+
}
225229

226230
if (page == NULL && index->table->is_encrypted) {
227231
mtr_commit(&mtr);

storage/innobase/btr/btr0scrub.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,13 @@ btr_scrub_page(
750750
mtr_t* mtr) /*!< in: mtr */
751751
{
752752
/* recheck if page needs scrubbing (knowing allocation status) */
753-
int needs_scrubbing = btr_page_needs_scrubbing(
754-
scrub_data, block, allocated);
755-
if (needs_scrubbing != BTR_SCRUB_PAGE) {
753+
int needs_scrubbing = BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
754+
755+
if (block) {
756+
btr_page_needs_scrubbing(scrub_data, block, allocated);
757+
}
758+
759+
if (!block || needs_scrubbing != BTR_SCRUB_PAGE) {
756760
mtr_commit(mtr);
757761
return needs_scrubbing;
758762
}
@@ -784,7 +788,12 @@ btr_scrub_page(
784788
return BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
785789
}
786790

787-
if (btr_page_get_index_id(buf_block_get_frame(block)) !=
791+
buf_frame_t* frame = NULL;
792+
793+
if (block) {
794+
frame = buf_block_get_frame(block);
795+
}
796+
if (!frame || btr_page_get_index_id(frame) !=
788797
scrub_data->current_index->id) {
789798
/* page has been reallocated to new index */
790799
mtr_commit(mtr);

storage/xtradb/btr/btr0cur.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,15 +1795,24 @@ btr_cur_pessimistic_insert(
17951795
btr_cur_get_page_zip(cursor),
17961796
thr_get_trx(thr)->id, mtr);
17971797
}
1798-
if (!page_rec_is_infimum(btr_cur_get_rec(cursor))
1799-
|| btr_page_get_prev(
1800-
buf_block_get_frame(
1801-
btr_cur_get_block(cursor)), mtr)
1802-
== FIL_NULL) {
1798+
1799+
if (!page_rec_is_infimum(btr_cur_get_rec(cursor))) {
18031800
/* split and inserted need to call
18041801
lock_update_insert() always. */
18051802
inherit = TRUE;
18061803
}
1804+
1805+
buf_block_t* block = btr_cur_get_block(cursor);
1806+
buf_frame_t* frame = NULL;
1807+
1808+
if (block) {
1809+
frame = buf_block_get_frame(block);
1810+
}
1811+
/* split and inserted need to call
1812+
lock_update_insert() always. */
1813+
if (frame && btr_page_get_prev(frame, mtr) == FIL_NULL) {
1814+
inherit = TRUE;
1815+
}
18071816
}
18081817

18091818
#ifdef BTR_CUR_ADAPT

storage/xtradb/btr/btr0defragment.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ btr_defragment_add_index(
220220

221221
mtr_start(&mtr);
222222
// Load index rood page.
223-
page_t* page = btr_page_get(space, zip_size, page_no,
224-
RW_NO_LATCH, index, &mtr);
223+
buf_block_t* block = btr_block_get(space, zip_size, page_no, RW_NO_LATCH, index, &mtr);
224+
page_t* page = NULL;
225+
226+
if (block) {
227+
page = buf_block_get_frame(block);
228+
}
225229

226230
if (page == NULL && index->table->is_encrypted) {
227231
mtr_commit(&mtr);

storage/xtradb/btr/btr0scrub.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,13 @@ btr_scrub_page(
750750
mtr_t* mtr) /*!< in: mtr */
751751
{
752752
/* recheck if page needs scrubbing (knowing allocation status) */
753-
int needs_scrubbing = btr_page_needs_scrubbing(
754-
scrub_data, block, allocated);
755-
if (needs_scrubbing != BTR_SCRUB_PAGE) {
753+
int needs_scrubbing = BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
754+
755+
if (block) {
756+
btr_page_needs_scrubbing(scrub_data, block, allocated);
757+
}
758+
759+
if (!block || needs_scrubbing != BTR_SCRUB_PAGE) {
756760
mtr_commit(mtr);
757761
return needs_scrubbing;
758762
}
@@ -784,7 +788,12 @@ btr_scrub_page(
784788
return BTR_SCRUB_SKIP_PAGE_AND_CLOSE_TABLE;
785789
}
786790

787-
if (btr_page_get_index_id(buf_block_get_frame(block)) !=
791+
buf_frame_t* frame = NULL;
792+
793+
if (block) {
794+
frame = buf_block_get_frame(block);
795+
}
796+
if (!frame || btr_page_get_index_id(frame) !=
788797
scrub_data->current_index->id) {
789798
/* page has been reallocated to new index */
790799
mtr_commit(mtr);

0 commit comments

Comments
 (0)