summaryrefslogtreecommitdiffstats
path: root/api/src/glfs-fops.c
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-21 18:21:25 +0300
committerAmar Tumballi <amarts@redhat.com>2018-08-24 16:26:36 +0000
commit036327d9e963c84a5222f8d1c7598ab36ad46a4b (patch)
tree3bbe76dab6bbf265381237024dc484d6d31f1f40 /api/src/glfs-fops.c
parent5acb74d7daee0fc5c501a82e604ec2abdb3cf88a (diff)
glfs-fops.c, glfs.c: strncpy() -> sprintf(), reduce strlen()'s
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(). Also, save the result of strlen() and re-use it when possible. Compile-tested only! Change-Id: I4ecfb359cf0efaafeab245a8138f526b21613231 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'api/src/glfs-fops.c')
-rw-r--r--api/src/glfs-fops.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
index ee4271fb4dc..611cb14d9eb 100644
--- a/api/src/glfs-fops.c
+++ b/api/src/glfs-fops.c
@@ -3205,8 +3205,7 @@ gf_dirent_to_dirent (gf_dirent_t *gf_dirent, struct dirent *dirent)
dirent->d_namlen = strlen (gf_dirent->d_name);
#endif
- strncpy (dirent->d_name, gf_dirent->d_name, NAME_MAX);
- dirent->d_name[NAME_MAX] = 0;
+ snprintf (dirent->d_name, NAME_MAX, "%s", gf_dirent->d_name);
}
@@ -4679,8 +4678,7 @@ retry:
goto out;
if (loc.path) {
- strncpy (retpath, loc.path, PATH_MAX);
- retpath[PATH_MAX] = 0;
+ snprintf (retpath, PATH_MAX, "%s", loc.path);
}
out: