Skip to content

Commit 4d01dd7

Browse files
author
Jan Lindström
committed
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to temporary file
After review cleanup.
1 parent 4aeec72 commit 4d01dd7

File tree

6 files changed

+34
-66
lines changed

6 files changed

+34
-66
lines changed

storage/innobase/log/log0crypt.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ log_blocks_crypt(
246246
ENCRYPTION_FLAG_DECRYPT
247247
@param[in] offs offset to block
248248
@param[in] space_id tablespace id
249-
@return true if successfull, false in case of failure
249+
@return true if successful, false in case of failure
250250
*/
251251
static
252252
bool

storage/innobase/row/row0log.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ struct row_log_t {
182182
dict_table_t* table; /*!< table that is being rebuilt,
183183
or NULL when this is a secondary
184184
index that is being created online */
185-
dict_index_t* index; /*!< index to be build */
186185
bool same_pk;/*!< whether the definition of the PRIMARY KEY
187186
has remained the same */
188187
const dtuple_t* add_cols;
@@ -385,7 +384,7 @@ row_log_online_op(
385384
byte_offset,
386385
index->table->space)) {
387386
log->error = DB_DECRYPTION_FAILED;
388-
goto err_exit;
387+
goto write_failed;
389388
}
390389

391390
srv_stats.n_rowlog_blocks_encrypted.inc();
@@ -479,13 +478,15 @@ static MY_ATTRIBUTE((nonnull))
479478
void
480479
row_log_table_close_func(
481480
/*=====================*/
482-
row_log_t* log, /*!< in/out: online rebuild log */
481+
dict_index_t* index, /*!< in/out: online rebuilt index */
483482
#ifdef UNIV_DEBUG
484483
const byte* b, /*!< in: end of log record */
485484
#endif /* UNIV_DEBUG */
486485
ulint size, /*!< in: size of log record */
487486
ulint avail) /*!< in: available size for log record */
488487
{
488+
row_log_t* log = index->online_log;
489+
489490
ut_ad(mutex_own(&log->mutex));
490491

491492
if (size >= avail) {
@@ -520,7 +521,7 @@ row_log_table_close_func(
520521
srv_sort_buf_size,
521522
log->crypt_tail,
522523
byte_offset,
523-
log->index->table->space)) {
524+
index->table->space)) {
524525
log->error = DB_DECRYPTION_FAILED;
525526
goto err_exit;
526527
}
@@ -559,11 +560,11 @@ row_log_table_close_func(
559560
}
560561

561562
#ifdef UNIV_DEBUG
562-
# define row_log_table_close(log, b, size, avail) \
563-
row_log_table_close_func(log, b, size, avail)
563+
# define row_log_table_close(index, b, size, avail) \
564+
row_log_table_close_func(index, b, size, avail)
564565
#else /* UNIV_DEBUG */
565566
# define row_log_table_close(log, b, size, avail) \
566-
row_log_table_close_func(log, size, avail)
567+
row_log_table_close_func(index, size, avail)
567568
#endif /* UNIV_DEBUG */
568569

569570
/******************************************************//**
@@ -735,8 +736,7 @@ row_log_table_delete(
735736
b += ext_size;
736737
}
737738

738-
row_log_table_close(
739-
index->online_log, b, mrec_size, avail_size);
739+
row_log_table_close(index, b, mrec_size, avail_size);
740740
}
741741

742742
func_exit:
@@ -859,8 +859,7 @@ row_log_table_low_redundant(
859859
b + extra_size, index, tuple->fields, tuple->n_fields);
860860
b += size;
861861

862-
row_log_table_close(
863-
index->online_log, b, mrec_size, avail_size);
862+
row_log_table_close(index, b, mrec_size, avail_size);
864863
}
865864

866865
mem_heap_free(heap);
@@ -969,8 +968,7 @@ row_log_table_low(
969968
memcpy(b, rec, rec_offs_data_size(offsets));
970969
b += rec_offs_data_size(offsets);
971970

972-
row_log_table_close(
973-
index->online_log, b, mrec_size, avail_size);
971+
row_log_table_close(index, b, mrec_size, avail_size);
974972
}
975973
}
976974

@@ -2678,7 +2676,7 @@ row_log_table_apply_ops(
26782676

26792677
/* If encryption is enabled decrypt buffer after reading it
26802678
from file system. */
2681-
if (log_tmp_is_encrypted()) {
2679+
if (success && log_tmp_is_encrypted()) {
26822680
if (!log_tmp_block_decrypt(buf,
26832681
srv_sort_buf_size,
26842682
index->online_log->crypt_head,
@@ -2999,7 +2997,6 @@ row_log_allocate(
29992997
log->head.total = 0;
30002998
log->path = path;
30012999
log->crypt_tail = log->crypt_head = NULL;
3002-
log->index = index;
30033000
dict_index_set_online_status(index, ONLINE_INDEX_CREATION);
30043001
index->online_log = log;
30053002

@@ -3548,7 +3545,7 @@ row_log_apply_ops(
35483545

35493546
/* If encryption is enabled decrypt buffer after reading it
35503547
from file system. */
3551-
if (log_tmp_is_encrypted()) {
3548+
if (success && log_tmp_is_encrypted()) {
35523549
if (!log_tmp_block_decrypt(buf,
35533550
srv_sort_buf_size,
35543551
index->online_log->crypt_head,

storage/innobase/row/row0merge.cc

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,8 @@ row_merge_read(
880880
success = os_file_read_no_error_handling_int_fd(fd, buf,
881881
ofs, srv_sort_buf_size);
882882

883-
/* For encrypted tables, decrypt data after reading and copy data */
884-
if (log_tmp_is_encrypted()) {
883+
/* If encryption is enabled decrypt buffer */
884+
if (success && log_tmp_is_encrypted()) {
885885
if (!log_tmp_block_decrypt(buf, srv_sort_buf_size,
886886
crypt_buf, ofs, space)) {
887887
return (FALSE);
@@ -3915,22 +3915,13 @@ row_merge_build_indexes(
39153915
DBUG_RETURN(DB_OUT_OF_MEMORY);
39163916
}
39173917

3918-
/* Get crypt data from tablespace if present. We should be protected
3919-
from concurrent DDL (e.g. drop table) by MDL-locks. */
3920-
fil_space_t* space = fil_space_acquire(new_table->space);
3921-
3922-
if (!space) {
3923-
DBUG_RETURN(DB_TABLESPACE_NOT_FOUND);
3924-
}
3925-
3926-
/* If tablespace is encrypted, allocate additional buffer for
3918+
/* If temporal log file is encrypted allocate memory for
39273919
encryption/decryption. */
39283920
if (log_tmp_is_encrypted()) {
39293921
crypt_block = static_cast<row_merge_block_t*>(
39303922
os_mem_alloc_large(&block_size));
39313923

39323924
if (crypt_block == NULL) {
3933-
fil_space_release(space);
39343925
DBUG_RETURN(DB_OUT_OF_MEMORY);
39353926
}
39363927
}
@@ -4310,9 +4301,5 @@ row_merge_build_indexes(
43104301
}
43114302
}
43124303

4313-
if (space) {
4314-
fil_space_release(space);
4315-
}
4316-
43174304
DBUG_RETURN(error);
43184305
}

storage/xtradb/log/log0crypt.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ log_blocks_crypt(
245245
ENCRYPTION_FLAG_DECRYPT
246246
@param[in] offs offset to block
247247
@param[in] space_id tablespace id
248-
@return true if successfull, false in case of failure
248+
@return true if successful, false in case of failure
249249
*/
250250
static
251251
bool

storage/xtradb/row/row0log.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ struct row_log_t {
182182
dict_table_t* table; /*!< table that is being rebuilt,
183183
or NULL when this is a secondary
184184
index that is being created online */
185-
dict_index_t* index; /*!< index to be build */
186185
bool same_pk;/*!< whether the definition of the PRIMARY KEY
187186
has remained the same */
188187
const dtuple_t* add_cols;
@@ -385,7 +384,7 @@ row_log_online_op(
385384
byte_offset,
386385
index->table->space)) {
387386
log->error = DB_DECRYPTION_FAILED;
388-
goto err_exit;
387+
goto write_failed;
389388
}
390389

391390
srv_stats.n_rowlog_blocks_encrypted.inc();
@@ -479,13 +478,15 @@ static MY_ATTRIBUTE((nonnull))
479478
void
480479
row_log_table_close_func(
481480
/*=====================*/
482-
row_log_t* log, /*!< in/out: online rebuild log */
481+
dict_index_t* index, /*!< in/out: online rebuilt index */
483482
#ifdef UNIV_DEBUG
484483
const byte* b, /*!< in: end of log record */
485484
#endif /* UNIV_DEBUG */
486485
ulint size, /*!< in: size of log record */
487486
ulint avail) /*!< in: available size for log record */
488487
{
488+
row_log_t* log = index->online_log;
489+
489490
ut_ad(mutex_own(&log->mutex));
490491

491492
if (size >= avail) {
@@ -520,7 +521,7 @@ row_log_table_close_func(
520521
srv_sort_buf_size,
521522
log->crypt_tail,
522523
byte_offset,
523-
log->index->table->space)) {
524+
index->table->space)) {
524525
log->error = DB_DECRYPTION_FAILED;
525526
goto err_exit;
526527
}
@@ -559,11 +560,11 @@ row_log_table_close_func(
559560
}
560561

561562
#ifdef UNIV_DEBUG
562-
# define row_log_table_close(log, b, size, avail) \
563-
row_log_table_close_func(log, b, size, avail)
563+
# define row_log_table_close(index, b, size, avail) \
564+
row_log_table_close_func(index, b, size, avail)
564565
#else /* UNIV_DEBUG */
565566
# define row_log_table_close(log, b, size, avail) \
566-
row_log_table_close_func(log, size, avail)
567+
row_log_table_close_func(index, size, avail)
567568
#endif /* UNIV_DEBUG */
568569

569570
/******************************************************//**
@@ -735,8 +736,7 @@ row_log_table_delete(
735736
b += ext_size;
736737
}
737738

738-
row_log_table_close(
739-
index->online_log, b, mrec_size, avail_size);
739+
row_log_table_close(index, b, mrec_size, avail_size);
740740
}
741741

742742
func_exit:
@@ -859,8 +859,7 @@ row_log_table_low_redundant(
859859
b + extra_size, index, tuple->fields, tuple->n_fields);
860860
b += size;
861861

862-
row_log_table_close(
863-
index->online_log, b, mrec_size, avail_size);
862+
row_log_table_close(index, b, mrec_size, avail_size);
864863
}
865864

866865
mem_heap_free(heap);
@@ -969,8 +968,7 @@ row_log_table_low(
969968
memcpy(b, rec, rec_offs_data_size(offsets));
970969
b += rec_offs_data_size(offsets);
971970

972-
row_log_table_close(
973-
index->online_log, b, mrec_size, avail_size);
971+
row_log_table_close(index, b, mrec_size, avail_size);
974972
}
975973
}
976974

@@ -2675,7 +2673,7 @@ row_log_table_apply_ops(
26752673

26762674
/* If encryption is enabled decrypt buffer after reading it
26772675
from file system. */
2678-
if (log_tmp_is_encrypted()) {
2676+
if (success && log_tmp_is_encrypted()) {
26792677
if (!log_tmp_block_decrypt(buf,
26802678
srv_sort_buf_size,
26812679
index->online_log->crypt_head,
@@ -2996,7 +2994,6 @@ row_log_allocate(
29962994
log->head.total = 0;
29972995
log->path = path;
29982996
log->crypt_tail = log->crypt_head = NULL;
2999-
log->index = index;
30002997
dict_index_set_online_status(index, ONLINE_INDEX_CREATION);
30012998
index->online_log = log;
30022999

@@ -3542,7 +3539,7 @@ row_log_apply_ops(
35423539

35433540
/* If encryption is enabled decrypt buffer after reading it
35443541
from file system. */
3545-
if (log_tmp_is_encrypted()) {
3542+
if (success && log_tmp_is_encrypted()) {
35463543
if (!log_tmp_block_decrypt(buf,
35473544
srv_sort_buf_size,
35483545
index->online_log->crypt_head,

storage/xtradb/row/row0merge.cc

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ row_merge_read(
887887
success = os_file_read_no_error_handling_int_fd(fd, buf,
888888
ofs, srv_sort_buf_size);
889889

890-
/* For encrypted tables, decrypt data after reading and copy data */
891-
if (log_tmp_is_encrypted()) {
890+
/* If encryption is enabled decrypt buffer */
891+
if (success && log_tmp_is_encrypted()) {
892892
if (!log_tmp_block_decrypt(buf, srv_sort_buf_size,
893893
crypt_buf, ofs, space)) {
894894
return (FALSE);
@@ -3918,22 +3918,13 @@ row_merge_build_indexes(
39183918
DBUG_RETURN(DB_OUT_OF_MEMORY);
39193919
}
39203920

3921-
/* Get crypt data from tablespace if present. We should be protected
3922-
from concurrent DDL (e.g. drop table) by MDL-locks. */
3923-
fil_space_t* space = fil_space_acquire(new_table->space);
3924-
3925-
if (!space) {
3926-
DBUG_RETURN(DB_TABLESPACE_NOT_FOUND);
3927-
}
3928-
3929-
/* If temporal log file is encrypted allocate memory for
3921+
/* If temporary log file is encrypted allocate memory for
39303922
encryption/decryption. */
39313923
if (log_tmp_is_encrypted()) {
39323924
crypt_block = static_cast<row_merge_block_t*>(
39333925
os_mem_alloc_large(&block_size));
39343926

39353927
if (crypt_block == NULL) {
3936-
fil_space_release(space);
39373928
DBUG_RETURN(DB_OUT_OF_MEMORY);
39383929
}
39393930
}
@@ -4313,9 +4304,5 @@ row_merge_build_indexes(
43134304
}
43144305
}
43154306

4316-
if (space) {
4317-
fil_space_release(space);
4318-
}
4319-
43204307
DBUG_RETURN(error);
43214308
}

0 commit comments

Comments
 (0)