Commit 3d1b6f68 authored by Marko Mäkelä's avatar Marko Mäkelä

Mariabackup: Ensure NUL termination in strncpy()

parent 630199e7
......@@ -2352,7 +2352,8 @@ static void rocksdb_copy_back() {
return;
char rocksdb_home_dir[FN_REFLEN];
if (xb_rocksdb_datadir && is_abs_path(xb_rocksdb_datadir)) {
strncpy(rocksdb_home_dir, xb_rocksdb_datadir, sizeof(rocksdb_home_dir));
strncpy(rocksdb_home_dir, xb_rocksdb_datadir, sizeof rocksdb_home_dir - 1);
rocksdb_home_dir[sizeof rocksdb_home_dir - 1] = '\0';
} else {
snprintf(rocksdb_home_dir, sizeof(rocksdb_home_dir), "%s/%s", mysql_data_home,
xb_rocksdb_datadir?trim_dotslash(xb_rocksdb_datadir): ROCKSDB_BACKUP_DIR);
......
......@@ -2550,8 +2550,9 @@ xtrabackup_copy_datafile(fil_node_t* node, uint thread_n, const char *dest_name=
goto error;
}
strncpy(dst_name, (dest_name)?dest_name : cursor.rel_path, sizeof(dst_name));
strncpy(dst_name, dest_name ? dest_name : cursor.rel_path,
sizeof dst_name - 1);
dst_name[sizeof dst_name - 1] = '\0';
/* Setup the page write filter */
if (xtrabackup_incremental) {
......@@ -2871,7 +2872,8 @@ static void dbug_mariabackup_event(const char *event,const char *key)
if (slash)
*slash = '_';
} else {
strncpy(envvar, event, sizeof(envvar));
strncpy(envvar, event, sizeof envvar - 1);
envvar[sizeof envvar - 1] = '\0';
}
char *sql = getenv(envvar);
if (sql) {
......@@ -4536,7 +4538,8 @@ void backup_fix_ddl(void)
const char *extension = is_remote ? ".isl" : ".ibd";
name.append(extension);
char buf[FN_REFLEN];
strncpy(buf, name.c_str(), sizeof(buf));
strncpy(buf, name.c_str(), sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
const char *dbname = buf;
char *p = strchr(buf, '/');
if (p == 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment