summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-03-06 11:22:27 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2019-03-06 11:22:27 +0200
commitb7612116850d1968dc34d5a2d7b812ebfecf67f2 (patch)
tree31d4fa47eba2ca312848ee1d4833da839aa9cc8c /extra
parentb21930fb0fc1a1986adac0e2a911005ad709bfe7 (diff)
downloadmariadb-git-b7612116850d1968dc34d5a2d7b812ebfecf67f2.tar.gz
MDEV-18659: Fix string truncation/overflow in InnoDB and XtraDB
Fix the warnings issued by GCC 8 -Wstringop-truncation and -Wstringop-overflow in InnoDB and XtraDB. This work is motivated by Jan Lindström. The patch mainly differs from his original one as follows: (1) We remove explicit initialization of stack-allocated string buffers. The minimum amount of initialization that is needed is a terminating NUL character. (2) GCC issues a warning for invoking strncpy(dest, src, sizeof dest) because if strlen(src) >= sizeof dest, there would be no terminating NUL byte in dest. We avoid this problem by invoking strncpy() with a limit that is 1 less than the buffer size, and by always writing NUL to the last byte of the buffer. (3) We replace strncpy() with memcpy() or strcpy() in those cases when the result is functionally equivalent. Note: fts_fetch_index_words() never deals with len==UNIV_SQL_NULL. This was enforced by an assertion that limits the maximum length to FTS_MAX_WORD_LEN. Also, the encoding that InnoDB uses for the compressed fulltext index is not byte-order agnostic, that is, InnoDB data files that use FULLTEXT INDEX are not portable between big-endian and little-endian systems.
Diffstat (limited to 'extra')
-rw-r--r--extra/mariabackup/backup_copy.cc6
-rw-r--r--extra/mariabackup/encryption_plugin.cc8
-rw-r--r--extra/mariabackup/fil_cur.cc6
-rw-r--r--extra/mariabackup/xtrabackup.cc15
4 files changed, 21 insertions, 14 deletions
diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc
index 895ef744ea1..a998ebecd41 100644
--- a/extra/mariabackup/backup_copy.cc
+++ b/extra/mariabackup/backup_copy.cc
@@ -501,7 +501,8 @@ datafile_open(const char *file, datafile_cur_t *cursor, uint thread_n)
5.6+. We want to make "local" copies for the backup. */
strncpy(cursor->rel_path,
xb_get_relative_path(cursor->abs_path, FALSE),
- sizeof(cursor->rel_path));
+ (sizeof cursor->rel_path) - 1);
+ cursor->rel_path[(sizeof cursor->rel_path) - 1] = '\0';
cursor->file = os_file_create_simple_no_error_handling(0,
cursor->abs_path,
@@ -642,8 +643,7 @@ mkdirp(const char *pathname, int Flags, myf MyFlags)
/* make a parent directory path */
if (!(parent= (char *)malloc(len)))
return(-1);
- strncpy(parent, pathname, len);
- parent[len-1]= 0;
+ memcpy(parent, pathname, len);
for (p = parent + strlen(parent);
!is_path_separator(*p) && p != parent; p--);
diff --git a/extra/mariabackup/encryption_plugin.cc b/extra/mariabackup/encryption_plugin.cc
index 8f7741b057a..b5acd385d0a 100644
--- a/extra/mariabackup/encryption_plugin.cc
+++ b/extra/mariabackup/encryption_plugin.cc
@@ -67,7 +67,8 @@ void encryption_plugin_backup_init(MYSQL *mysql)
/* Required to load the plugin later.*/
add_to_plugin_load_list(plugin_load.c_str());
- strncpy(opt_plugin_dir, dir, FN_REFLEN);
+ strncpy(opt_plugin_dir, dir, FN_REFLEN - 1);
+ opt_plugin_dir[FN_REFLEN - 1] = '\0';
oss << "plugin_dir=" << '"' << dir << '"' << endl;
@@ -133,7 +134,10 @@ void encryption_plugin_prepare_init(int argc, char **argv)
add_to_plugin_load_list(xb_plugin_load);
if (xb_plugin_dir)
- strncpy(opt_plugin_dir, xb_plugin_dir, FN_REFLEN);
+ {
+ strncpy(opt_plugin_dir, xb_plugin_dir, FN_REFLEN - 1);
+ opt_plugin_dir[FN_REFLEN - 1] = '\0';
+ }
char **new_argv = new char *[argc + 1];
new_argv[0] = XTRABACKUP_EXE;
diff --git a/extra/mariabackup/fil_cur.cc b/extra/mariabackup/fil_cur.cc
index 46465575a48..ce9aaecfc9c 100644
--- a/extra/mariabackup/fil_cur.cc
+++ b/extra/mariabackup/fil_cur.cc
@@ -152,7 +152,8 @@ xb_fil_cur_open(
cursor->space_id = node->space->id;
cursor->is_system = !fil_is_user_tablespace_id(node->space->id);
- strncpy(cursor->abs_path, node->name, sizeof(cursor->abs_path));
+ strncpy(cursor->abs_path, node->name, (sizeof cursor->abs_path) - 1);
+ cursor->abs_path[(sizeof cursor->abs_path) - 1] = '\0';
/* Get the relative path for the destination tablespace name, i.e. the
one that can be appended to the backup root directory. Non-system
@@ -160,7 +161,8 @@ xb_fil_cur_open(
5.6+. We want to make "local" copies for the backup. */
strncpy(cursor->rel_path,
xb_get_relative_path(cursor->abs_path, cursor->is_system),
- sizeof(cursor->rel_path));
+ (sizeof cursor->rel_path) - 1);
+ cursor->rel_path[(sizeof cursor->rel_path) - 1] = '\0';
/* In the backup mode we should already have a tablespace handle created
by fil_load_single_table_tablespace() unless it is a system
diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc
index 2d28a6caa84..fb897e407e2 100644
--- a/extra/mariabackup/xtrabackup.cc
+++ b/extra/mariabackup/xtrabackup.cc
@@ -2251,8 +2251,9 @@ check_if_skip_table(
return(FALSE);
}
- strncpy(buf, dbname, FN_REFLEN);
- buf[tbname - 1 - dbname] = 0;
+ strncpy(buf, dbname, FN_REFLEN - 1);
+ buf[FN_REFLEN - 1] = '\0';
+ buf[tbname - 1 - dbname] = '\0';
const skip_database_check_result skip_database =
check_if_skip_database(buf);
@@ -2260,7 +2261,6 @@ check_if_skip_table(
return (TRUE);
}
- buf[FN_REFLEN - 1] = '\0';
buf[tbname - 1 - dbname] = '.';
/* Check if there's a suffix in the table name. If so, truncate it. We
@@ -4990,7 +4990,8 @@ xtrabackup_apply_delta(
}
dst_path[strlen(dst_path) - 6] = '\0';
- strncpy(space_name, filename, FN_REFLEN);
+ strncpy(space_name, filename, FN_REFLEN - 1);
+ space_name[FN_REFLEN - 1] = '\0';
space_name[strlen(space_name) - 6] = 0;
if (!get_meta_path(src_path, meta_path)) {
@@ -6036,7 +6037,8 @@ skip_check:
p = next + 1;
}
info_file_path[len - 4] = 0;
- strncpy(table_name, prev, FN_REFLEN);
+ strncpy(table_name, prev, FN_REFLEN - 1);
+ table_name[FN_REFLEN - 1] = '\0';
info_file_path[len - 4] = '.';
@@ -6072,8 +6074,7 @@ skip_check:
mach_write_to_4(page , 0x78706f72UL);
mach_write_to_4(page + 4, 0x74696e66UL);/*"xportinf"*/
mach_write_to_4(page + 8, n_index);
- strncpy((char *) page + 12,
- table_name, 500);
+ strncpy((char *) page + 12, table_name, FN_REFLEN);
msg("mariabackup: export metadata of "
"table '%s' to file `%s` "