Quiet new build warnings that appear with GCC8, mainly related
to the length of string buffers not being long enough (in theory)
for the maximum possible string sizes, even if this never actually
is possible in practice.
Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I83a955fc68f3e03fe84622ddf1cedfb30d5916ac
Reviewed-on: https://review.whamcloud.com/34662
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
16 files changed:
if (ip_range_len >= LNET_MAX_STR_LEN) {
snprintf(err_str,
LNET_MAX_STR_LEN,
if (ip_range_len >= LNET_MAX_STR_LEN) {
snprintf(err_str,
LNET_MAX_STR_LEN,
- "\"cannot parse ip_range '%s'\"", ip_range);
+ "\"too long ip_range '%s'\"", nidstr);
err_str[LNET_MAX_STR_LEN - 1] = '\0';
rc = LUSTRE_CFG_RC_BAD_PARAM;
goto out;
err_str[LNET_MAX_STR_LEN - 1] = '\0';
rc = LUSTRE_CFG_RC_BAD_PARAM;
goto out;
if (rc != LUSTRE_CFG_RC_NO_ERR) {
snprintf(err_str,
LNET_MAX_STR_LEN,
if (rc != LUSTRE_CFG_RC_NO_ERR) {
snprintf(err_str,
LNET_MAX_STR_LEN,
- "\"cannot parse ip_range '%s'\"", ip_range);
+ "\"cannot parse ip_range '%.100s'\"", ip_range);
err_str[LNET_MAX_STR_LEN - 1] = '\0';
rc = LUSTRE_CFG_RC_BAD_PARAM;
goto out;
err_str[LNET_MAX_STR_LEN - 1] = '\0';
rc = LUSTRE_CFG_RC_BAD_PARAM;
goto out;
if (!entry || !entry->cy_valuestring)
continue;
if (!entry || !entry->cy_valuestring)
continue;
- nids[num] = calloc(strlen(entry->cy_valuestring) + 1, 1);
+ nids[num] = strdup(entry->cy_valuestring);
if (!nids[num]) {
rc = LUSTRE_CFG_RC_OUT_OF_MEM;
goto failed;
}
if (!nids[num]) {
rc = LUSTRE_CFG_RC_OUT_OF_MEM;
goto failed;
}
- strncpy(nids[num], entry->cy_valuestring,
- strlen(entry->cy_valuestring));
int
jt_lst_new_session(int argc, char **argv)
{
int
jt_lst_new_session(int argc, char **argv)
{
- char buf[LST_NAME_SIZE];
+ char buf[LST_NAME_SIZE * 2 + 1];
char *name;
int optidx = 0;
int timeout = 300;
char *name;
int optidx = 0;
int timeout = 300;
static int ct_save_stripe(int src_fd, const char *src, const char *dst)
{
static int ct_save_stripe(int src_fd, const char *src, const char *dst)
{
- char lov_file[PATH_MAX];
+ char lov_file[PATH_MAX + 8];
char lov_buf[XATTR_SIZE_MAX];
struct lov_user_md *lum;
int rc;
char lov_buf[XATTR_SIZE_MAX];
struct lov_user_md *lum;
int rc;
static int ct_load_stripe(const char *src, void *lovea, size_t *lovea_size)
{
static int ct_load_stripe(const char *src, void *lovea, size_t *lovea_size)
{
- char lov_file[PATH_MAX];
+ char lov_file[PATH_MAX + 4];
}
if (rename_needed == true) {
}
if (rename_needed == true) {
- char tmp_src[PATH_MAX];
- char tmp_dst[PATH_MAX];
+ char tmp_src[PATH_MAX + 8];
+ char tmp_dst[PATH_MAX + 8];
/* atomically replace old archived file */
ct_path_archive(src, sizeof(src), opt.o_hsm_root,
/* atomically replace old archived file */
ct_path_archive(src, sizeof(src), opt.o_hsm_root,
"target_obd", ¶m);
if (rc == 0) {
strncpy(buffer, param.gl_pathv[0],
"target_obd", ¶m);
if (rc == 0) {
strncpy(buffer, param.gl_pathv[0],
}
} else {
return -EINVAL;
}
} else {
return -EINVAL;
/* sanity check of target list */
if (param->lsp_is_specific) {
/* sanity check of target list */
if (param->lsp_is_specific) {
- char ostname[MAX_OBD_NAME + 1];
+ char ostname[MAX_OBD_NAME + 64];
bool found = false;
int i;
bool found = false;
int i;
/* sanity check of target list */
if (param->lsp_is_specific) {
/* sanity check of target list */
if (param->lsp_is_specific) {
- char mdtname[MAX_OBD_NAME + 1];
+ char mdtname[MAX_OBD_NAME + 64];
bool found = false;
int i;
bool found = false;
int i;
lfm->lfm_length = len;
lfm->lfm_type = type;
lfm->lfm_flags = flags;
lfm->lfm_length = len;
lfm->lfm_type = type;
lfm->lfm_flags = flags;
- strncpy(lfm->lfm_value, value, len);
+ memcpy(lfm->lfm_value, value, len);
filename = basename(namepath);
dir = dirname(dirpath);
filename = basename(namepath);
dir = dirname(dirpath);
/* If the path isn't set return the first one we find */
if (path == NULL || strlen(path) == 0) {
/* If the path isn't set return the first one we find */
if (path == NULL || strlen(path) == 0) {
- strncpy(mntdir, mnt.mnt_dir, strlen(mnt.mnt_dir));
+ strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1);
mntdir[strlen(mnt.mnt_dir)] = '\0';
if ((want & WANT_FSNAME) && fsname != NULL) {
strncpy(fsname, ptr, ptr_end - ptr);
mntdir[strlen(mnt.mnt_dir)] = '\0';
if ((want & WANT_FSNAME) && fsname != NULL) {
strncpy(fsname, ptr, ptr_end - ptr);
/* Otherwise find the longest matching path */
} else if ((strlen(path) >= mntlen) && (mntlen >= len) &&
(strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
/* Otherwise find the longest matching path */
} else if ((strlen(path) >= mntlen) && (mntlen >= len) &&
(strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
- strncpy(mntdir, mnt.mnt_dir, strlen(mnt.mnt_dir));
+ strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir));
mntdir[strlen(mnt.mnt_dir)] = '\0';
len = mntlen;
if ((want & WANT_FSNAME) && fsname != NULL) {
mntdir[strlen(mnt.mnt_dir)] = '\0';
len = mntlen;
if ((want & WANT_FSNAME) && fsname != NULL) {
/* Found it */
if (rc == 0) {
if ((want & WANT_PATH) && path != NULL) {
/* Found it */
if (rc == 0) {
if ((want & WANT_PATH) && path != NULL) {
- strncpy(path, mntdir, strlen(mntdir));
+ strncpy(path, mntdir, PATH_MAX);
path[strlen(mntdir)] = '\0';
}
if (want & WANT_FD) {
path[strlen(mntdir)] = '\0';
}
if (want & WANT_FD) {
int flags)
{
char mntdir[PATH_MAX];
int flags)
{
char mntdir[PATH_MAX];
+ char path[PATH_MAX + 64];
int rc;
rc = llapi_search_mounts(lustre_dir, 0, mntdir, NULL);
int rc;
rc = llapi_search_mounts(lustre_dir, 0, mntdir, NULL);
- strncpy(buf, path, size);
+ strncpy(buf, path, size - 1);
p = strrchr(buf, '/');
if (p != NULL) {
p = strrchr(buf, '/');
if (p != NULL) {
}
if (strlen(pattern) + 3 > sizeof(pattern))
return -E2BIG;
}
if (strlen(pattern) + 3 > sizeof(pattern))
return -E2BIG;
- strncat(pattern, "-*", sizeof(pattern));
+ strncat(pattern, "-*", sizeof(pattern) - 1);
break;
case FILTER_BY_FS_NAME:
rc = snprintf(pattern, sizeof(pattern) - 1, "%s-*", filter);
break;
case FILTER_BY_FS_NAME:
rc = snprintf(pattern, sizeof(pattern) - 1, "%s-*", filter);
}
while ((d = readdir(slaves_dir)) != NULL) {
}
while ((d = readdir(slaves_dir)) != NULL) {
+ char path[PATH_MAX * 2];
int rc2;
if (d->d_type != DT_LNK)
int rc2;
if (d->d_type != DT_LNK)
{
struct stat st;
char sys_path[PATH_MAX];
{
struct stat st;
char sys_path[PATH_MAX];
- char partition_path[PATH_MAX];
+ char partition_path[PATH_MAX + sizeof("partition")];
char *real_sys_path = NULL;
int rc;
char *real_sys_path = NULL;
int rc;
fd = mkstemp(log);
if (fd >= 0) {
close(fd);
fd = mkstemp(log);
if (fd >= 0) {
close(fd);
- strncat(cmd, " >", 2);
- strncat(cmd, log, strlen(log));
+ strncat(cmd, " >", cmdsz);
+ strncat(cmd, log, cmdsz);
- strncat(cmd, " 2>&1", 5);
+ strncat(cmd, " 2>&1", cmdsz - strlen(cmd));
/* Can't use popen because we need the rv of the command */
rc = system(cmd);
/* Can't use popen because we need the rv of the command */
rc = system(cmd);
if (*ptr == '/') {
ptr1 = strrchr(ptr, '/');
*ptr1 = '\0';
if (*ptr == '/') {
ptr1 = strrchr(ptr, '/');
*ptr1 = '\0';
- len = strlen(ptr);
- st->st_dir = malloc(len + 1);
+ st->st_dir = strdup(ptr);
if (!st->st_dir) {
rc = -ENOMEM;
goto out;
}
if (!st->st_dir) {
rc = -ENOMEM;
goto out;
}
-
- strncpy(st->st_dir, ptr, len);
- st->st_dir[len] = '\0';
- len = strlen(ptr);
- st->st_pool = malloc(len + 1);
+ st->st_pool = strdup(ptr);
if (!st->st_pool) {
rc = -ENOMEM;
goto out;
}
if (!st->st_pool) {
rc = -ENOMEM;
goto out;
}
- strncpy(st->st_pool, ptr, len);
- st->st_pool[len] = '\0';
-
/* Format of label:
* fsname-<role><index> or <role><index> */
ptr = strrchr(label, '-');
/* Format of label:
* fsname-<role><index> or <role><index> */
ptr = strrchr(label, '-');
static int snapshot_handle_string_option(char **dst, const char *option,
const char *opt_name)
{
static int snapshot_handle_string_option(char **dst, const char *option,
const char *opt_name)
{
if (*dst && *dst != snapshot_rsh_default) {
fprintf(stderr,
"%s option has been specified repeatedly.\n", opt_name);
return -EINVAL;
}
if (*dst && *dst != snapshot_rsh_default) {
fprintf(stderr,
"%s option has been specified repeatedly.\n", opt_name);
return -EINVAL;
}
- len = strlen(option);
- *dst = malloc(len + 1);
if (!*dst)
return -ENOMEM;
if (!*dst)
return -ENOMEM;
-
- strncpy(*dst, option, len);
- (*dst)[len] = '\0';
static int mdt0_is_lustre_snapshot(struct snapshot_instance *si)
{
struct snapshot_target *st = si->si_mdt0;
static int mdt0_is_lustre_snapshot(struct snapshot_instance *si)
{
struct snapshot_target *st = si->si_mdt0;
- char buf[MAX_BUF_SIZE];
+ char buf[MAX_BUF_SIZE * 3];
char *fsname, int fslen)
{
struct snapshot_target *st = si->si_mdt0;
char *fsname, int fslen)
{
struct snapshot_target *st = si->si_mdt0;
- char buf[MAX_BUF_SIZE];
+ char buf[MAX_BUF_SIZE * 3];
static int snapshot_get_mgsnode(struct snapshot_instance *si,
char *node, int size)
{
static int snapshot_get_mgsnode(struct snapshot_instance *si,
char *node, int size)
{
- char buf[MAX_BUF_SIZE];
+ char buf[MAX_BUF_SIZE * 2];
struct snapshot_target *st;
FILE *fp;
int rc = 0;
struct snapshot_target *st;
FILE *fp;
int rc = 0;
static int snapshot_exists_check(struct snapshot_instance *si,
struct snapshot_target *st)
{
static int snapshot_exists_check(struct snapshot_instance *si,
struct snapshot_target *st)
{
- char buf[MAX_BUF_SIZE];
+ char buf[MAX_BUF_SIZE * 2];
struct snapshot_target *st,
char *cmd, int size)
{
struct snapshot_target *st,
char *cmd, int size)
{
- char buf[MAX_BUF_SIZE];
+ char buf[MAX_BUF_SIZE * 3];
FILE *fp;
int len = 0;
int rc = 0;
FILE *fp;
int len = 0;
int rc = 0;
/* child */
if (pid == 0) {
/* child */
if (pid == 0) {
- char cmd[MAX_BUF_SIZE];
+ char cmd[MAX_BUF_SIZE * 2];
memset(cmd, 0, sizeof(cmd));
if (si->si_force)
memset(cmd, 0, sizeof(cmd));
if (si->si_force)
/* child */
if (pid == 0) {
/* child */
if (pid == 0) {
- char cmd[MAX_BUF_SIZE];
+ char cmd[MAX_BUF_SIZE * 5];
memset(cmd, 0, sizeof(cmd));
if (si->si_new_ssname && si->si_comment)
memset(cmd, 0, sizeof(cmd));
if (si->si_new_ssname && si->si_comment)
static int snapshot_list_one(struct snapshot_instance *si,
struct snapshot_target *st)
{
static int snapshot_list_one(struct snapshot_instance *si,
struct snapshot_target *st)
{
- char buf[MAX_BUF_SIZE];
+ char buf[MAX_BUF_SIZE * 3];
struct list_head list_sub_items;
struct list_sub_item *lsi;
struct list_head list_sub_items;
struct list_sub_item *lsi;
- char buf[MAX_BUF_SIZE];
+ char buf[MAX_BUF_SIZE * 2];
- strncpy(lsi->lsi_ssname, buf, len);
- lsi->lsi_ssname[len] = '\0';
+ memcpy(lsi->lsi_ssname, buf, len + 1);
list_add(&lsi->lsi_list, &list_sub_items);
}
list_add(&lsi->lsi_list, &list_sub_items);
}
static int snapshot_mount_target(struct snapshot_instance *si,
struct snapshot_target *st, const char *optstr)
{
static int snapshot_mount_target(struct snapshot_instance *si,
struct snapshot_target *st, const char *optstr)
{
- char cmd[MAX_BUF_SIZE];
+ char cmd[MAX_BUF_SIZE * 2];
tmp = realloc(param_name, suffix_len + strlen(param_name) + 1);
if (tmp != NULL) {
param_name = tmp;
tmp = realloc(param_name, suffix_len + strlen(param_name) + 1);
if (tmp != NULL) {
param_name = tmp;
- strncat(param_name, suffix, suffix_len);
+ strncat(param_name, suffix,
+ strlen(param_name) + suffix_len);
enum paramtype confset = PT_NONE;
int param = PS_NONE;
char *tmp;
enum paramtype confset = PT_NONE;
int param = PS_NONE;
char *tmp;
- char parameter[PARAM_SZ];
- char value[PARAM_SZ];
- char device[PARAM_SZ];
+ char parameter[PARAM_SZ + 1];
+ char value[PARAM_SZ + 1];
+ char device[PARAM_SZ + 1];
file = fopen(filename, "rb");
yaml_parser_initialize(&parser);
file = fopen(filename, "rb");
yaml_parser_initialize(&parser);
*/
tmp = strchrnul(parameter, '=');
if (*tmp == '=') {
*/
tmp = strchrnul(parameter, '=');
if (*tmp == '=') {
- strncpy(value, tmp+1, sizeof(value));
+ strncpy(value, tmp + 1, sizeof(value) - 1);
*tmp = '\0';
param |= PS_VAL_SET;
} else {
*tmp = '\0';
param |= PS_VAL_SET;
} else {
receipt of a signal */
int abort_on_err = 0;
receipt of a signal */
int abort_on_err = 0;
-char rsync[PATH_MAX];
-char rsync_ver[PATH_MAX];
+char rsync[PATH_MAX + 128];
+char rsync_ver[PATH_MAX * 2];
struct lr_parent_child_list *parents;
FILE *debug_log;
struct lr_parent_child_list *parents;
FILE *debug_log;
return EINVAL;
strncpy(&search[1], param, keyend - param + 1);
} else {
return EINVAL;
strncpy(&search[1], param, keyend - param + 1);
} else {
- strncpy(&search[1], param, strlen(param));
- strncat(search, "=", 1);
+ snprintf(search + 1, sizeof(search) - 1, "%s=", param);
free(options);
return EINVAL;
}
free(options);
return EINVAL;
}
- strncpy(mop->mo_skpath, val + 1, strlen(val + 1));
+ strncpy(mop->mo_skpath, val + 1,
+ sizeof(mop->mo_skpath) - 1);
#endif
} else if (parse_one_option(opt, flagp) == 0) {
/* pass this on as an option */
#endif
} else if (parse_one_option(opt, flagp) == 0) {
/* pass this on as an option */
{
struct module_backfs_ops *ops;
#ifdef PLUGIN_DIR
{
struct module_backfs_ops *ops;
#ifdef PLUGIN_DIR
- char *error, filename[512], fsname[512], *name;
+ char *error, filename[PATH_MAX], fsname[512], *name;
void *handle;
/* This deals with duplicate ldd_mount_types resolving to same OSD layer
void *handle;
/* This deals with duplicate ldd_mount_types resolving to same OSD layer
{
struct lustre_disk_data *ldd = &mop->mo_ldd;
struct lr_server_data lsd;
{
struct lustre_disk_data *ldd = &mop->mo_ldd;
struct lr_server_data lsd;
char cfg_dir[128];
DIR *dir = NULL;
struct dirent64 *dirent;
char cfg_dir[128];
DIR *dir = NULL;
struct dirent64 *dirent;
nl_oom();
s[0] = '\0';
for (i = 0; i < nl->count; i++) {
nl_oom();
s[0] = '\0';
for (i = 0; i < nl->count; i++) {
- if (i > 0)
- strncat(s, sep, len);
- strncat(s, nl->nids[i], len);
+ int cur = strlen(s);
+ snprintf(s + cur, len - cur, "%s%s",
+ i > 0 ? sep : "", nl->nids[i]);
"-%s", savedn);
free(savedn);
}
"-%s", savedn);
free(savedn);
}
+ strncat(s, "]", max_len - strlen(s));
if (lnet)
snprintf(s + strlen(s), max_len - strlen(s),
"@%s", lnet);
if (lnet)
snprintf(s + strlen(s), max_len - strlen(s),
"@%s", lnet);
memset(bc, 0, sizeof(*bc));
bc->bc_version = BARRIER_VERSION_V1;
bc->bc_cmd = BC_STAT;
memset(bc, 0, sizeof(*bc));
bc->bc_version = BARRIER_VERSION_V1;
bc->bc_cmd = BC_STAT;
- strncpy(bc->bc_name, fsname, sizeof(bc->bc_name));
+ strncpy(bc->bc_name, fsname, sizeof(bc->bc_name) - 1);
data.ioc_inlbuf1 = (char *)bc;
data.ioc_inllen1 = sizeof(*bc);
memset(buf, 0, sizeof(rawbuf));
data.ioc_inlbuf1 = (char *)bc;
data.ioc_inllen1 = sizeof(*bc);
memset(buf, 0, sizeof(rawbuf));