Whamcloud - gitweb
LU-11233 utils: fix build warnings for gcc8 62/34662/9
authorAlex Zhuravlev <bzzz@whamcloud.com>
Mon, 15 Apr 2019 13:25:50 +0000 (16:25 +0300)
committerOleg Drokin <green@whamcloud.com>
Sat, 25 May 2019 05:12:33 +0000 (05:12 +0000)
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:
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lst.c
lustre/utils/lhsmtool_posix.c
lustre/utils/liblustreapi.c
lustre/utils/liblustreapi_layout.c
lustre/utils/liblustreapi_param.c
lustre/utils/libmount_utils_ldiskfs.c
lustre/utils/lr_reader.c
lustre/utils/lsnapshot.c
lustre/utils/lustre_cfg.c
lustre/utils/lustre_rsync.c
lustre/utils/mkfs_lustre.c
lustre/utils/mount_lustre.c
lustre/utils/mount_utils.c
lustre/utils/nidlist.c
lustre/utils/obd.c

index 29a5283..bdcda35 100644 (file)
@@ -719,7 +719,7 @@ static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
        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;
@@ -747,7 +747,7 @@ static int lnet_expr2ips(char *nidstr, __u32 *ip_list,
        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;
@@ -4313,13 +4313,11 @@ static int yaml_copy_peer_nids(struct cYAML *nids_entry, char ***nidsppp,
                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));
                num++;
        }
        rc = num;
                num++;
        }
        rc = num;
index 7d11a24..6c8aaea 100644 (file)
@@ -535,7 +535,7 @@ lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid)
 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;
index 083d4c6..93e72be 100644 (file)
@@ -469,7 +469,7 @@ static int ct_mkdir_p(const char *path)
 
 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;
@@ -529,7 +529,7 @@ err_cleanup:
 
 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];
        int      rc;
        int      fd;
 
        int      rc;
        int      fd;
 
@@ -1042,8 +1042,8 @@ static int ct_archive(const struct hsm_action_item *hai, const long hal_flags)
        }
 
        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,
index d21f8da..a738211 100644 (file)
@@ -568,7 +568,7 @@ int llapi_search_tgt(char *fsname, char *poolname, char *tgtname, bool is_mdt)
                                           "target_obd", &param);
                if (rc == 0) {
                        strncpy(buffer, param.gl_pathv[0],
                                           "target_obd", &param);
                if (rc == 0) {
                        strncpy(buffer, param.gl_pathv[0],
-                               sizeof(buffer));
+                               sizeof(buffer) - 1);
                }
        } else {
                return -EINVAL;
                }
        } else {
                return -EINVAL;
@@ -680,7 +680,7 @@ int llapi_file_open_param(const char *name, int flags, mode_t mode,
 
        /* 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;
 
@@ -961,7 +961,7 @@ static int verify_dir_param(const char *name,
 
        /* 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;
 
@@ -1219,7 +1219,7 @@ int llapi_dir_create_foreign(const char *name, mode_t mode, __u32 type,
        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);
@@ -1369,7 +1369,7 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
 
                 /* 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);
@@ -1380,7 +1380,7 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
                /* 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) {
@@ -1395,7 +1395,7 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
        /* 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) {
@@ -5949,7 +5949,7 @@ int llapi_open_by_fid(const char *lustre_dir, const struct lu_fid *fid,
                      int flags)
 {
        char mntdir[PATH_MAX];
                      int flags)
 {
        char mntdir[PATH_MAX];
-       char path[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);
index b967356..bb1b5fc 100644 (file)
@@ -775,7 +775,7 @@ static void get_parent_dir(const char *path, char *buf, size_t size)
 {
        char *p;
 
 {
        char *p;
 
-       strncpy(buf, path, size);
+       strncpy(buf, path, size - 1);
        p = strrchr(buf, '/');
 
        if (p != NULL) {
        p = strrchr(buf, '/');
 
        if (p != NULL) {
index 6c3a48d..3dd79cd 100644 (file)
@@ -83,7 +83,7 @@ get_lustre_param_path(const char *obd_type, const char *filter,
                }
                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);
index 15f79bf..a3c4900 100644 (file)
@@ -1253,7 +1253,7 @@ static int tune_block_dev_slaves(const char *sys_path, struct mount_opts *mop)
        }
 
        while ((d = readdir(slaves_dir)) != NULL) {
        }
 
        while ((d = readdir(slaves_dir)) != NULL) {
-               char path[PATH_MAX];
+               char path[PATH_MAX * 2];
                int rc2;
 
                if (d->d_type != DT_LNK)
                int rc2;
 
                if (d->d_type != DT_LNK)
@@ -1277,7 +1277,7 @@ static int tune_block_dev(const char *src, struct mount_opts *mop)
 {
        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;
 
index a6d94c1..21be0d6 100644 (file)
@@ -86,10 +86,10 @@ int run_command(char *cmd, size_t cmdsz)
        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);
index 3d79674..5de39b2 100644 (file)
@@ -244,28 +244,20 @@ static int snapshot_load_conf_ldev(struct snapshot_instance *si, char *buf,
        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';
                ptr = ptr1 + 1;
        }
 
                ptr = ptr1 + 1;
        }
 
-       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, '-');
@@ -658,21 +650,15 @@ static void snapshot_unload_conf(struct snapshot_instance *si)
 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)
 {
-       int len;
-
        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);
+       *dst = strdup(option);
        if (!*dst)
                return -ENOMEM;
        if (!*dst)
                return -ENOMEM;
-
-       strncpy(*dst, option, len);
-       (*dst)[len] = '\0';
        return 0;
 }
 
        return 0;
 }
 
@@ -922,7 +908,7 @@ static char *snapshot_first_skip_blank(char *buf)
 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];
        FILE *fp;
        int rc;
 
        FILE *fp;
        int rc;
 
@@ -1007,7 +993,7 @@ static int snapshot_get_fsname(struct snapshot_instance *si,
                               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];
        FILE *fp;
        int rc = 0;
 
        FILE *fp;
        int rc = 0;
 
@@ -1033,7 +1019,7 @@ static int snapshot_get_fsname(struct snapshot_instance *si,
 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;
@@ -1061,7 +1047,7 @@ static int snapshot_get_mgsnode(struct snapshot_instance *si,
 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];
        FILE *fp;
        int rc = 0;
 
        FILE *fp;
        int rc = 0;
 
@@ -1128,7 +1114,7 @@ static int snapshot_inherit_prop(struct snapshot_instance *si,
                                 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;
@@ -1597,7 +1583,7 @@ static int __snapshot_destroy(struct snapshot_instance *si,
 
                /* 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)
@@ -1801,7 +1787,7 @@ static int __snapshot_modify(struct snapshot_instance *si,
 
                /* 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)
@@ -1942,7 +1928,7 @@ static void snapshot_list_usage(void)
 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];
        FILE *fp;
        int rc;
 
        FILE *fp;
        int rc;
 
@@ -2074,7 +2060,7 @@ static int snapshot_list_all(struct snapshot_instance *si)
 
        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];
        FILE *fp;
        int rc = 0;
 
        FILE *fp;
        int rc = 0;
 
@@ -2101,8 +2087,7 @@ static int snapshot_list_all(struct snapshot_instance *si)
                        break;
                }
 
                        break;
                }
 
-               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);
        }
 
@@ -2198,7 +2183,7 @@ static int snapshot_mount_check(struct snapshot_instance *si, char *fsname,
 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];
        char name[8];
        int rc;
 
        char name[8];
        int rc;
 
index 02f3fa1..ef7d3d6 100644 (file)
@@ -669,7 +669,8 @@ display_name(const char *filename, struct stat *st, struct param_opts *popt)
                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);
                }
        }
 
                }
        }
 
@@ -1423,9 +1424,9 @@ int lcfg_setparam_yaml(char *func, char *filename)
        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);
@@ -1488,7 +1489,7 @@ int lcfg_setparam_yaml(char *func, char *filename)
                         */
                        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 {
index 2c7add8..550ffdd 100644 (file)
@@ -192,8 +192,8 @@ int quit;       /* Flag to stop processing the changelog; set on the
                    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;
index 6e25b13..a054cf6 100644 (file)
@@ -292,8 +292,7 @@ static int erase_param(const char *const buf, const char *const param,
                        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);
        }
 
        while (1) {
        }
 
        while (1) {
index 1acd635..beb42a8 100644 (file)
@@ -348,7 +348,8 @@ int parse_options(struct mount_opts *mop, char *orig_options,
                                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 */
index e294463..4a2a7d4 100644 (file)
@@ -546,7 +546,7 @@ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type)
 {
        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
@@ -977,7 +977,7 @@ int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt,
 {
        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 filepnm[128];
+       char filepnm[132];
        char cfg_dir[128];
        DIR *dir = NULL;
        struct dirent64 *dirent;
        char cfg_dir[128];
        DIR *dir = NULL;
        struct dirent64 *dirent;
index 87450a4..3af3c30 100644 (file)
@@ -262,9 +262,9 @@ char *nl_string(NIDList nl, char *sep)
                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]);
        }
        return s;
 }
        }
        return s;
 }
@@ -312,7 +312,7 @@ static void nl_strxcat(char *s, char **nids, int len, const int max_len)
                                         "-%s", savedn);
                                free(savedn);
                        }
                                         "-%s", savedn);
                                free(savedn);
                        }
-                       strncat(s, "]", 1);
+                       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);
index 3825730..2f81597 100644 (file)
@@ -4548,7 +4548,7 @@ int __jt_barrier_stat(const char *fsname, struct barrier_ctl *bc)
        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));