Skip to content

Commit

Permalink
MDEV-12634: Uninitialised ROW_MERGE_RESERVE_SIZE bytes written to tem…
Browse files Browse the repository at this point in the history
…porary file

After review cleanup.
  • Loading branch information
Jan Lindström committed Sep 28, 2017
1 parent 4aeec72 commit 4d01dd7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 66 deletions.
2 changes: 1 addition & 1 deletion storage/innobase/log/log0crypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ log_blocks_crypt(
ENCRYPTION_FLAG_DECRYPT
@param[in] offs offset to block
@param[in] space_id tablespace id
@return true if successfull, false in case of failure
@return true if successful, false in case of failure
*/
static
bool
Expand Down
29 changes: 13 additions & 16 deletions storage/innobase/row/row0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ struct row_log_t {
dict_table_t* table; /*!< table that is being rebuilt,
or NULL when this is a secondary
index that is being created online */
dict_index_t* index; /*!< index to be build */
bool same_pk;/*!< whether the definition of the PRIMARY KEY
has remained the same */
const dtuple_t* add_cols;
Expand Down Expand Up @@ -385,7 +384,7 @@ row_log_online_op(
byte_offset,
index->table->space)) {
log->error = DB_DECRYPTION_FAILED;
goto err_exit;
goto write_failed;
}

srv_stats.n_rowlog_blocks_encrypted.inc();
Expand Down Expand Up @@ -479,13 +478,15 @@ static MY_ATTRIBUTE((nonnull))
void
row_log_table_close_func(
/*=====================*/
row_log_t* log, /*!< in/out: online rebuild log */
dict_index_t* index, /*!< in/out: online rebuilt index */
#ifdef UNIV_DEBUG
const byte* b, /*!< in: end of log record */
#endif /* UNIV_DEBUG */
ulint size, /*!< in: size of log record */
ulint avail) /*!< in: available size for log record */
{
row_log_t* log = index->online_log;

ut_ad(mutex_own(&log->mutex));

if (size >= avail) {
Expand Down Expand Up @@ -520,7 +521,7 @@ row_log_table_close_func(
srv_sort_buf_size,
log->crypt_tail,
byte_offset,
log->index->table->space)) {
index->table->space)) {
log->error = DB_DECRYPTION_FAILED;
goto err_exit;
}
Expand Down Expand Up @@ -559,11 +560,11 @@ row_log_table_close_func(
}

#ifdef UNIV_DEBUG
# define row_log_table_close(log, b, size, avail) \
row_log_table_close_func(log, b, size, avail)
# define row_log_table_close(index, b, size, avail) \
row_log_table_close_func(index, b, size, avail)
#else /* UNIV_DEBUG */
# define row_log_table_close(log, b, size, avail) \
row_log_table_close_func(log, size, avail)
row_log_table_close_func(index, size, avail)
#endif /* UNIV_DEBUG */

/******************************************************//**
Expand Down Expand Up @@ -735,8 +736,7 @@ row_log_table_delete(
b += ext_size;
}

row_log_table_close(
index->online_log, b, mrec_size, avail_size);
row_log_table_close(index, b, mrec_size, avail_size);
}

func_exit:
Expand Down Expand Up @@ -859,8 +859,7 @@ row_log_table_low_redundant(
b + extra_size, index, tuple->fields, tuple->n_fields);
b += size;

row_log_table_close(
index->online_log, b, mrec_size, avail_size);
row_log_table_close(index, b, mrec_size, avail_size);
}

mem_heap_free(heap);
Expand Down Expand Up @@ -969,8 +968,7 @@ row_log_table_low(
memcpy(b, rec, rec_offs_data_size(offsets));
b += rec_offs_data_size(offsets);

row_log_table_close(
index->online_log, b, mrec_size, avail_size);
row_log_table_close(index, b, mrec_size, avail_size);
}
}

Expand Down Expand Up @@ -2678,7 +2676,7 @@ row_log_table_apply_ops(

/* If encryption is enabled decrypt buffer after reading it
from file system. */
if (log_tmp_is_encrypted()) {
if (success && log_tmp_is_encrypted()) {
if (!log_tmp_block_decrypt(buf,
srv_sort_buf_size,
index->online_log->crypt_head,
Expand Down Expand Up @@ -2999,7 +2997,6 @@ row_log_allocate(
log->head.total = 0;
log->path = path;
log->crypt_tail = log->crypt_head = NULL;
log->index = index;
dict_index_set_online_status(index, ONLINE_INDEX_CREATION);
index->online_log = log;

Expand Down Expand Up @@ -3548,7 +3545,7 @@ row_log_apply_ops(

/* If encryption is enabled decrypt buffer after reading it
from file system. */
if (log_tmp_is_encrypted()) {
if (success && log_tmp_is_encrypted()) {
if (!log_tmp_block_decrypt(buf,
srv_sort_buf_size,
index->online_log->crypt_head,
Expand Down
19 changes: 3 additions & 16 deletions storage/innobase/row/row0merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,8 @@ row_merge_read(
success = os_file_read_no_error_handling_int_fd(fd, buf,
ofs, srv_sort_buf_size);

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

/* Get crypt data from tablespace if present. We should be protected
from concurrent DDL (e.g. drop table) by MDL-locks. */
fil_space_t* space = fil_space_acquire(new_table->space);

if (!space) {
DBUG_RETURN(DB_TABLESPACE_NOT_FOUND);
}

/* If tablespace is encrypted, allocate additional buffer for
/* If temporal log file is encrypted allocate memory for
encryption/decryption. */
if (log_tmp_is_encrypted()) {
crypt_block = static_cast<row_merge_block_t*>(
os_mem_alloc_large(&block_size));

if (crypt_block == NULL) {
fil_space_release(space);
DBUG_RETURN(DB_OUT_OF_MEMORY);
}
}
Expand Down Expand Up @@ -4310,9 +4301,5 @@ row_merge_build_indexes(
}
}

if (space) {
fil_space_release(space);
}

DBUG_RETURN(error);
}
2 changes: 1 addition & 1 deletion storage/xtradb/log/log0crypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ log_blocks_crypt(
ENCRYPTION_FLAG_DECRYPT
@param[in] offs offset to block
@param[in] space_id tablespace id
@return true if successfull, false in case of failure
@return true if successful, false in case of failure
*/
static
bool
Expand Down
29 changes: 13 additions & 16 deletions storage/xtradb/row/row0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ struct row_log_t {
dict_table_t* table; /*!< table that is being rebuilt,
or NULL when this is a secondary
index that is being created online */
dict_index_t* index; /*!< index to be build */
bool same_pk;/*!< whether the definition of the PRIMARY KEY
has remained the same */
const dtuple_t* add_cols;
Expand Down Expand Up @@ -385,7 +384,7 @@ row_log_online_op(
byte_offset,
index->table->space)) {
log->error = DB_DECRYPTION_FAILED;
goto err_exit;
goto write_failed;
}

srv_stats.n_rowlog_blocks_encrypted.inc();
Expand Down Expand Up @@ -479,13 +478,15 @@ static MY_ATTRIBUTE((nonnull))
void
row_log_table_close_func(
/*=====================*/
row_log_t* log, /*!< in/out: online rebuild log */
dict_index_t* index, /*!< in/out: online rebuilt index */
#ifdef UNIV_DEBUG
const byte* b, /*!< in: end of log record */
#endif /* UNIV_DEBUG */
ulint size, /*!< in: size of log record */
ulint avail) /*!< in: available size for log record */
{
row_log_t* log = index->online_log;

ut_ad(mutex_own(&log->mutex));

if (size >= avail) {
Expand Down Expand Up @@ -520,7 +521,7 @@ row_log_table_close_func(
srv_sort_buf_size,
log->crypt_tail,
byte_offset,
log->index->table->space)) {
index->table->space)) {
log->error = DB_DECRYPTION_FAILED;
goto err_exit;
}
Expand Down Expand Up @@ -559,11 +560,11 @@ row_log_table_close_func(
}

#ifdef UNIV_DEBUG
# define row_log_table_close(log, b, size, avail) \
row_log_table_close_func(log, b, size, avail)
# define row_log_table_close(index, b, size, avail) \
row_log_table_close_func(index, b, size, avail)
#else /* UNIV_DEBUG */
# define row_log_table_close(log, b, size, avail) \
row_log_table_close_func(log, size, avail)
row_log_table_close_func(index, size, avail)
#endif /* UNIV_DEBUG */

/******************************************************//**
Expand Down Expand Up @@ -735,8 +736,7 @@ row_log_table_delete(
b += ext_size;
}

row_log_table_close(
index->online_log, b, mrec_size, avail_size);
row_log_table_close(index, b, mrec_size, avail_size);
}

func_exit:
Expand Down Expand Up @@ -859,8 +859,7 @@ row_log_table_low_redundant(
b + extra_size, index, tuple->fields, tuple->n_fields);
b += size;

row_log_table_close(
index->online_log, b, mrec_size, avail_size);
row_log_table_close(index, b, mrec_size, avail_size);
}

mem_heap_free(heap);
Expand Down Expand Up @@ -969,8 +968,7 @@ row_log_table_low(
memcpy(b, rec, rec_offs_data_size(offsets));
b += rec_offs_data_size(offsets);

row_log_table_close(
index->online_log, b, mrec_size, avail_size);
row_log_table_close(index, b, mrec_size, avail_size);
}
}

Expand Down Expand Up @@ -2675,7 +2673,7 @@ row_log_table_apply_ops(

/* If encryption is enabled decrypt buffer after reading it
from file system. */
if (log_tmp_is_encrypted()) {
if (success && log_tmp_is_encrypted()) {
if (!log_tmp_block_decrypt(buf,
srv_sort_buf_size,
index->online_log->crypt_head,
Expand Down Expand Up @@ -2996,7 +2994,6 @@ row_log_allocate(
log->head.total = 0;
log->path = path;
log->crypt_tail = log->crypt_head = NULL;
log->index = index;
dict_index_set_online_status(index, ONLINE_INDEX_CREATION);
index->online_log = log;

Expand Down Expand Up @@ -3542,7 +3539,7 @@ row_log_apply_ops(

/* If encryption is enabled decrypt buffer after reading it
from file system. */
if (log_tmp_is_encrypted()) {
if (success && log_tmp_is_encrypted()) {
if (!log_tmp_block_decrypt(buf,
srv_sort_buf_size,
index->online_log->crypt_head,
Expand Down
19 changes: 3 additions & 16 deletions storage/xtradb/row/row0merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,8 @@ row_merge_read(
success = os_file_read_no_error_handling_int_fd(fd, buf,
ofs, srv_sort_buf_size);

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

/* Get crypt data from tablespace if present. We should be protected
from concurrent DDL (e.g. drop table) by MDL-locks. */
fil_space_t* space = fil_space_acquire(new_table->space);

if (!space) {
DBUG_RETURN(DB_TABLESPACE_NOT_FOUND);
}

/* If temporal log file is encrypted allocate memory for
/* If temporary log file is encrypted allocate memory for
encryption/decryption. */
if (log_tmp_is_encrypted()) {
crypt_block = static_cast<row_merge_block_t*>(
os_mem_alloc_large(&block_size));

if (crypt_block == NULL) {
fil_space_release(space);
DBUG_RETURN(DB_OUT_OF_MEMORY);
}
}
Expand Down Expand Up @@ -4313,9 +4304,5 @@ row_merge_build_indexes(
}
}

if (space) {
fil_space_release(space);
}

DBUG_RETURN(error);
}

0 comments on commit 4d01dd7

Please sign in to comment.