[Commits] 5e7d0af0293: MDEV-18659: Fix gcc-8 compiler warnings produced by -Wstringop-truncation and -Wstringop-overflow for InnoDB
revision-id: 5e7d0af0293ec0e8713efba6cf311e595f96e310 (mariadb-10.1.38-7-g5e7d0af0293) parent(s): 346e46089621e6951e076c82ed5690aa23dcb5fe author: Jan Lindström committer: Jan Lindström timestamp: 2019-02-20 15:26:27 +0200 message: MDEV-18659: Fix gcc-8 compiler warnings produced by -Wstringop-truncation and -Wstringop-overflow for InnoDB dict_table_rename_in_cache dict/dict0dict.cc:1870:11: warning: ‘char* strncpy(char*, const char*, size_t)’ output may be truncated copying 320 bytes from a string of length 654 [-Wstringop-truncation] Use memcpy instead as it is safe to read and copy MAX_TABLE_NAME_LEN characters as both old_name_cs_filename and old_name have allocated more space. fts_write_node Make sure than inserted word is not NULL. Note that there is similar assertions before we search stopwords or insert data. fts_fetch_index_words fts/fts0opt.cc:681:16: warning: ‘int __builtin_memcmp_eq(const void*, const void*, long unsigned int)’ specified size 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] dfield_get_len returns a ulint as it can return UNIV_SQL_NULL (ULINT32_UNDEFINED) and storing return value to short can cause overflow. However, NULL-values are not actually stored "word"-column in FTS-index. dict_create_add_foreign_id include/dict0crea.ic:71:11: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 340 equals destination size [-Wstringop-truncation] Add extra space for string constant to avoid this. row_rename_table_for_mysql row/row0mysql.cc:5190:10: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 320 equals destination size [-Wstringop-truncation] Add extra space for string constant to avoid this. log_online_setup_bitmap_file_range log/log0online.cc:1455:11: warning: ‘char* strncpy(char*, const char*, size_t)’ output may be truncated copying 512 bytes from a string of length 3999 [-Wstringop-truncation] Copy only FN_REFLEN - 1 characters as we will add string end marker there anyway. --- storage/innobase/dict/dict0dict.cc | 4 ++-- storage/innobase/fts/fts0fts.cc | 1 + storage/innobase/fts/fts0opt.cc | 10 +++++----- storage/innobase/include/dict0crea.ic | 2 +- storage/innobase/row/row0mysql.cc | 4 ++-- storage/xtradb/dict/dict0dict.cc | 6 +++--- storage/xtradb/fts/fts0fts.cc | 1 + storage/xtradb/fts/fts0opt.cc | 10 +++++----- storage/xtradb/include/dict0crea.ic | 2 +- storage/xtradb/log/log0online.cc | 2 +- storage/xtradb/row/row0mysql.cc | 4 ++-- 11 files changed, 24 insertions(+), 22 deletions(-) diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 06c6c3effab..d14a2320795 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -1861,7 +1861,7 @@ dict_table_rename_in_cache( /* The old table name in my_charset_filename is stored in old_name_cs_filename */ - strncpy(old_name_cs_filename, old_name, + memcpy(old_name_cs_filename, old_name, MAX_TABLE_NAME_LEN); if (strstr(old_name, TEMP_TABLE_PATH_PREFIX) == NULL) { @@ -1883,7 +1883,7 @@ dict_table_rename_in_cache( } else { /* Old name already in my_charset_filename */ - strncpy(old_name_cs_filename, old_name, + memcpy(old_name_cs_filename, old_name, MAX_TABLE_NAME_LEN); } } diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 75258bb8610..14ef9960cee 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -3830,6 +3830,7 @@ fts_write_node( info = pars_info_create(); } + ut_ad(word->f_len != UNIV_SQL_NULL); pars_info_bind_varchar_literal(info, "token", word->f_str, word->f_len); /* Convert to "storage" byte order. */ diff --git a/storage/innobase/fts/fts0opt.cc b/storage/innobase/fts/fts0opt.cc index 77293bc867a..2a97f0fa527 100644 --- a/storage/innobase/fts/fts0opt.cc +++ b/storage/innobase/fts/fts0opt.cc @@ -673,18 +673,18 @@ fts_fetch_index_words( fts_zip_t* zip = static_cast<fts_zip_t*>(user_arg); que_node_t* exp = sel_node->select_list; dfield_t* dfield = que_node_get_val(exp); - short len = static_cast<short>(dfield_get_len(dfield)); + ulint len = dfield_get_len(dfield); void* data = dfield_get_data(dfield); + ut_a(len <= FTS_MAX_WORD_LEN); + /* Skip the duplicate words. */ - if (zip->word.f_len == static_cast<ulint>(len) + if (zip->word.f_len == len && !memcmp(zip->word.f_str, data, len)) { return(TRUE); } - ut_a(len <= FTS_MAX_WORD_LEN); - memcpy(zip->word.f_str, data, len); zip->word.f_len = len; @@ -693,7 +693,7 @@ fts_fetch_index_words( /* The string is prefixed by len. */ zip->zp->next_in = reinterpret_cast<byte*>(&len); - zip->zp->avail_in = sizeof(len); + zip->zp->avail_in = sizeof(static_cast<short>(len)); /* Compress the word, create output blocks as necessary. */ while (zip->zp->avail_in > 0) { diff --git a/storage/innobase/include/dict0crea.ic b/storage/innobase/include/dict0crea.ic index 1cbaa47032b..88919fbd24c 100644 --- a/storage/innobase/include/dict0crea.ic +++ b/storage/innobase/include/dict0crea.ic @@ -65,7 +65,7 @@ dict_create_add_foreign_id( sprintf(id, "%s_ibfk_%lu", name, (ulong) (*id_nr)++); } else { - char table_name[MAX_TABLE_NAME_LEN + 20] = ""; + char table_name[MAX_TABLE_NAME_LEN + 21] = ""; uint errors = 0; strncpy(table_name, name, diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 2a9ade1da2c..84f30e226dd 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -5173,8 +5173,8 @@ row_rename_table_for_mysql( if (!new_is_tmp) { /* Rename all constraints. */ - char new_table_name[MAX_TABLE_NAME_LEN] = ""; - char old_table_utf8[MAX_TABLE_NAME_LEN] = ""; + char new_table_name[MAX_TABLE_NAME_LEN+1] = ""; + char old_table_utf8[MAX_TABLE_NAME_LEN+1] = ""; uint errors = 0; strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN); diff --git a/storage/xtradb/dict/dict0dict.cc b/storage/xtradb/dict/dict0dict.cc index 1c489d13f1a..3961e0c4639 100644 --- a/storage/xtradb/dict/dict0dict.cc +++ b/storage/xtradb/dict/dict0dict.cc @@ -1867,7 +1867,7 @@ dict_table_rename_in_cache( /* The old table name in my_charset_filename is stored in old_name_cs_filename */ - strncpy(old_name_cs_filename, old_name, + memcpy(old_name_cs_filename, old_name, MAX_TABLE_NAME_LEN); if (strstr(old_name, TEMP_TABLE_PATH_PREFIX) == NULL) { @@ -1889,7 +1889,7 @@ dict_table_rename_in_cache( } else { /* Old name already in my_charset_filename */ - strncpy(old_name_cs_filename, old_name, + memcpy(old_name_cs_filename, old_name, MAX_TABLE_NAME_LEN); } } @@ -1916,7 +1916,7 @@ dict_table_rename_in_cache( /* This is a generated >= 4.0.18 format id */ - char table_name[MAX_TABLE_NAME_LEN] = ""; + char table_name[MAX_TABLE_NAME_LEN+1] = ""; uint errors = 0; if (strlen(table->name) > strlen(old_name)) { diff --git a/storage/xtradb/fts/fts0fts.cc b/storage/xtradb/fts/fts0fts.cc index 02d81551e75..e6549e40232 100644 --- a/storage/xtradb/fts/fts0fts.cc +++ b/storage/xtradb/fts/fts0fts.cc @@ -3829,6 +3829,7 @@ fts_write_node( info = pars_info_create(); } + ut_ad(word->f_len != UNIV_SQL_NULL); pars_info_bind_varchar_literal(info, "token", word->f_str, word->f_len); /* Convert to "storage" byte order. */ diff --git a/storage/xtradb/fts/fts0opt.cc b/storage/xtradb/fts/fts0opt.cc index 77293bc867a..2a97f0fa527 100644 --- a/storage/xtradb/fts/fts0opt.cc +++ b/storage/xtradb/fts/fts0opt.cc @@ -673,18 +673,18 @@ fts_fetch_index_words( fts_zip_t* zip = static_cast<fts_zip_t*>(user_arg); que_node_t* exp = sel_node->select_list; dfield_t* dfield = que_node_get_val(exp); - short len = static_cast<short>(dfield_get_len(dfield)); + ulint len = dfield_get_len(dfield); void* data = dfield_get_data(dfield); + ut_a(len <= FTS_MAX_WORD_LEN); + /* Skip the duplicate words. */ - if (zip->word.f_len == static_cast<ulint>(len) + if (zip->word.f_len == len && !memcmp(zip->word.f_str, data, len)) { return(TRUE); } - ut_a(len <= FTS_MAX_WORD_LEN); - memcpy(zip->word.f_str, data, len); zip->word.f_len = len; @@ -693,7 +693,7 @@ fts_fetch_index_words( /* The string is prefixed by len. */ zip->zp->next_in = reinterpret_cast<byte*>(&len); - zip->zp->avail_in = sizeof(len); + zip->zp->avail_in = sizeof(static_cast<short>(len)); /* Compress the word, create output blocks as necessary. */ while (zip->zp->avail_in > 0) { diff --git a/storage/xtradb/include/dict0crea.ic b/storage/xtradb/include/dict0crea.ic index 1cbaa47032b..88919fbd24c 100644 --- a/storage/xtradb/include/dict0crea.ic +++ b/storage/xtradb/include/dict0crea.ic @@ -65,7 +65,7 @@ dict_create_add_foreign_id( sprintf(id, "%s_ibfk_%lu", name, (ulong) (*id_nr)++); } else { - char table_name[MAX_TABLE_NAME_LEN + 20] = ""; + char table_name[MAX_TABLE_NAME_LEN + 21] = ""; uint errors = 0; strncpy(table_name, name, diff --git a/storage/xtradb/log/log0online.cc b/storage/xtradb/log/log0online.cc index bc1667e1c20..43ed68cbd57 100644 --- a/storage/xtradb/log/log0online.cc +++ b/storage/xtradb/log/log0online.cc @@ -1453,7 +1453,7 @@ log_online_setup_bitmap_file_range( bitmap_files->files[array_pos].seq_num = file_seq_num; strncpy(bitmap_files->files[array_pos].name, - bitmap_dir_file_info.name, FN_REFLEN); + bitmap_dir_file_info.name, FN_REFLEN - 1); bitmap_files->files[array_pos].name[FN_REFLEN - 1] = '\0'; bitmap_files->files[array_pos].start_lsn diff --git a/storage/xtradb/row/row0mysql.cc b/storage/xtradb/row/row0mysql.cc index 93a4db98e7b..0ea2ae1b6d4 100644 --- a/storage/xtradb/row/row0mysql.cc +++ b/storage/xtradb/row/row0mysql.cc @@ -5183,8 +5183,8 @@ row_rename_table_for_mysql( if (!new_is_tmp) { /* Rename all constraints. */ - char new_table_name[MAX_TABLE_NAME_LEN] = ""; - char old_table_utf8[MAX_TABLE_NAME_LEN] = ""; + char new_table_name[MAX_TABLE_NAME_LEN+1] = ""; + char old_table_utf8[MAX_TABLE_NAME_LEN+1] = ""; uint errors = 0; strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN);
participants (1)
-
jan