From 773c8672ac787936f46c9b29cf5b2dab85e686b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Wed, 7 Nov 2018 13:15:12 +0100 Subject: [PATCH] cmsfs-fuse: Copy strings correctly using util_strlcpy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use util_strlcpy() instead of strncpy() to correctly copy strings. This fixes the following GCC8 compile warnings: cmsfs-fuse.c: In function ‘file_open’: cmsfs-fuse.c:604:2: warning: ‘strncpy’ specified bound 18 equals destination size [-Wstringop-truncation] strncpy(uc_name, name, MAX_FNAME); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmsfs-fuse.c: In function ‘lookup_file’: cmsfs-fuse.c:1570:2: warning: ‘strncpy’ specified bound 18 equals destination size [-Wstringop-truncation] strncpy(uc_name, name, MAX_FNAME); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmsfs-fuse.c: In function ‘cmsfs_open’: cmsfs-fuse.c:1854:3: warning: ‘strncpy’ specified bound 19 equals destination size [-Wstringop-truncation] strncpy(f->path, path, MAX_FNAME + 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmsfs-fuse.c: In function ‘delete_file’: cmsfs-fuse.c:2760:2: warning: ‘strncpy’ specified bound 18 equals destination size [-Wstringop-truncation] strncpy(file, path + 1, MAX_FNAME); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmsfs-fuse.c: In function ‘cmsfs_rename’: cmsfs-fuse.c:2850:2: warning: ‘strncpy’ specified bound 18 equals destination size [-Wstringop-truncation] strncpy(uc_old_name, path + 1, MAX_FNAME); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmsfs-fuse.c:2857:3: warning: ‘strncpy’ specified bound 19 equals destination size [-Wstringop-truncation] strncpy(f->path, new_path, MAX_FNAME + 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cmsfs-fuse.c: In function ‘cmsfs_create’: cmsfs-fuse.c:2111:2: warning: ‘strncpy’ specified bound 18 equals destination size [-Wstringop-truncation] strncpy(uc_name, path + 1, MAX_FNAME); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ config.c:68:2: warning: ‘strncpy’ specified bound 9 equals destination size [-Wstringop-truncation] strncpy(entry->name, name, MAX_TYPE_LEN); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Höppner --- cmsfs-fuse/cmsfs-fuse.c | 15 ++++++++------- cmsfs-fuse/config.c | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmsfs-fuse/cmsfs-fuse.c b/cmsfs-fuse/cmsfs-fuse.c index 59af7d26..090df680 100644 --- a/cmsfs-fuse/cmsfs-fuse.c +++ b/cmsfs-fuse/cmsfs-fuse.c @@ -36,6 +36,7 @@ #include #include "lib/util_base.h" +#include "lib/util_libc.h" #include "lib/util_list.h" #include "lib/zt_common.h" @@ -601,7 +602,7 @@ static struct file *file_open(const char *name) char uc_name[MAX_FNAME]; struct file *f; - strncpy(uc_name, name, MAX_FNAME); + util_strlcpy(uc_name, name, MAX_FNAME); str_toupper(uc_name); util_list_iterate(&open_file_list, f) @@ -1564,7 +1565,7 @@ static off_t lookup_file(const char *name, struct fst_entry *fst, int flag) off_t faddr = 0; int rc; - strncpy(uc_name, name, MAX_FNAME); + util_strlcpy(uc_name, name, MAX_FNAME); str_toupper(uc_name); if (flag == HIDE_UNLINKED && file_unlinked(uc_name)) @@ -1848,7 +1849,7 @@ static int cmsfs_open(const char *path, struct fuse_file_info *fi) if (f->wcache == NULL) return -ENOMEM; - strncpy(f->path, path, MAX_FNAME + 1); + util_strlcpy(f->path, path, MAX_FNAME + 1); str_toupper(f->path); f->use_count = 1; @@ -2105,7 +2106,7 @@ static int cmsfs_create(const char *path, mode_t mode, return rc; /* force uppercase */ - strncpy(uc_name, path + 1, MAX_FNAME); + util_strlcpy(uc_name, path + 1, MAX_FNAME); str_toupper(uc_name); rc = encode_edf_name(uc_name, fname, ftype); @@ -2754,7 +2755,7 @@ static int delete_file(const char *path) fst_last = find_last_fdir_entry(cmsfs.fdir, cmsfs.dir_levels); /* remove unlinked file from fcache */ - strncpy(file, path + 1, MAX_FNAME); + util_strlcpy(file, path + 1, MAX_FNAME); str_toupper(file); invalidate_htab_entry(file); @@ -2845,14 +2846,14 @@ static int cmsfs_rename(const char *path, const char *new_path) memcpy(&fst.name[0], fname, 8); memcpy(&fst.type[0], ftype, 8); - strncpy(uc_old_name, path + 1, MAX_FNAME); + util_strlcpy(uc_old_name, path + 1, MAX_FNAME); str_toupper(uc_old_name); invalidate_htab_entry(uc_old_name); /* update name in file object if the file is opened */ f = file_open(uc_old_name); if (f != NULL) { - strncpy(f->path, new_path, MAX_FNAME + 1); + util_strlcpy(f->path, new_path, MAX_FNAME + 1); str_toupper(f->path); memcpy(f->fst->name, fname, 8); memcpy(f->fst->type, ftype, 8); diff --git a/cmsfs-fuse/config.c b/cmsfs-fuse/config.c index 920d873e..8cebd933 100644 --- a/cmsfs-fuse/config.c +++ b/cmsfs-fuse/config.c @@ -19,6 +19,7 @@ #include #include +#include "lib/util_libc.h" #include "lib/zt_common.h" #include "cmsfs-fuse.h" @@ -65,7 +66,7 @@ static void add_filetype(char *name, struct util_list *list) entry = malloc(sizeof(*entry)); if (entry == NULL) DIE_PERROR("malloc failed"); - strncpy(entry->name, name, MAX_TYPE_LEN); + util_strlcpy(entry->name, name, MAX_TYPE_LEN); util_list_add_head(list, entry); }