diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2019-03-06 11:22:27 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2019-03-06 11:22:27 +0200 |
commit | b7612116850d1968dc34d5a2d7b812ebfecf67f2 (patch) | |
tree | 31d4fa47eba2ca312848ee1d4833da839aa9cc8c /extra/mariabackup/fil_cur.cc | |
parent | b21930fb0fc1a1986adac0e2a911005ad709bfe7 (diff) | |
download | mariadb-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/mariabackup/fil_cur.cc')
-rw-r--r-- | extra/mariabackup/fil_cur.cc | 6 |
1 files changed, 4 insertions, 2 deletions
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 |