diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-21 20:29:17 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 06:17:20 +0000 |
commit | cd1051789361bd07e248baf1bf0fbbe479cd4ae1 (patch) | |
tree | 97a0b5bc7b3f93dd3ed79dee38e106c987d73001 | |
parent | a1d61242baed1c2078707c401632719e756fcacb (diff) |
NFS server (mount3.c, nfs-inodes.c): strncpy()->sprintf(), reduce strlen()'s
xlators/nfs/server/src/mount3.c
xlators/nfs/server/src/nfs-inodes.c
strncpy may not be very efficient for short strings copied into
a large buffer: If the length of src is less than n,
strncpy() writes additional null bytes to dest to ensure
that a total of n bytes are written.
Instead, use snprintf().
Compile-tested only!
Change-Id: Ibe74ccdb67434e9a10fc1f21c0b4cd5e4b8cb589
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
-rw-r--r-- | xlators/nfs/server/src/mount3.c | 12 | ||||
-rw-r--r-- | xlators/nfs/server/src/nfs-inodes.c | 5 |
2 files changed, 8 insertions, 9 deletions
diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c index 85fc1d608c6..187c975081d 100644 --- a/xlators/nfs/server/src/mount3.c +++ b/xlators/nfs/server/src/mount3.c @@ -353,14 +353,14 @@ dont_add: ret = gf_store_retrieve_value (sh, key, &value); if (ret) break; - strncpy (me->hostname, value, MNTPATHLEN); + snprintf (me->hostname, MNTPATHLEN, "%s", value); GF_FREE (value); snprintf (key, 11 + MNTPATHLEN, "mountpoint-%d", idx); ret = gf_store_retrieve_value (sh, key, &value); if (ret) break; - strncpy (me->exname, value, MNTPATHLEN); + snprintf (me->exname, MNTPATHLEN, "%s", value); GF_FREE (value); idx++; @@ -599,7 +599,7 @@ mnt3svc_update_mountlist (struct mount3_state *ms, rpcsvc_request_t *req, update_rmtab = mount_open_rmtab (nfs->rmtab, &sh); - strncpy (me->exname, expname, MNTPATHLEN); + snprintf (me->exname, MNTPATHLEN, "%s", expname); /* Sometimes we don't care about the full path * so a NULL value for fullpath is valid. */ @@ -1561,7 +1561,7 @@ mnt3_resolve_subdir (rpcsvc_request_t *req, struct mount3_state *ms, mres->mstate = ms; mres->req = req; - strncpy (mres->remainingdir, subdir, MNTPATHLEN); + snprintf (mres->remainingdir, MNTPATHLEN, "%s", subdir); gf_path_strip_trailing_slashes (mres->remainingdir); if (gf_nfs_dvm_off (nfs_state (ms->nfsx))) @@ -3067,8 +3067,8 @@ mount3udp_add_mountlist (xlator_t *nfsx, char *host, char *export) if (!me) return -1; - strncpy (me->exname, export, MNTPATHLEN); - strncpy (me->hostname, host, MNTPATHLEN); + snprintf (me->exname, MNTPATHLEN, "%s", export); + snprintf (me->hostname, MNTPATHLEN, "%s", host); INIT_LIST_HEAD (&me->mlist); LOCK (&ms->mountlock); { diff --git a/xlators/nfs/server/src/nfs-inodes.c b/xlators/nfs/server/src/nfs-inodes.c index 515622a3d5c..91703c70a1f 100644 --- a/xlators/nfs/server/src/nfs-inodes.c +++ b/xlators/nfs/server/src/nfs-inodes.c @@ -43,11 +43,10 @@ nfl_inodes_init (struct nfs_fop_local *nfl, inode_t *inode, inode_t *parent, nfl->newparent = inode_ref (newparent); if (name) - strncpy (nfl->path, name, NFS_NAME_MAX); + snprintf (nfl->path, NFS_NAME_MAX, "%s", name); if (newname) - strncpy (nfl->newpath, newname, NFS_NAME_MAX); - + snprintf (nfl->newpath, NFS_NAME_MAX, "%s", newname); return; } |