diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-21 18:21:25 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-24 16:26:36 +0000 |
commit | 036327d9e963c84a5222f8d1c7598ab36ad46a4b (patch) | |
tree | 3bbe76dab6bbf265381237024dc484d6d31f1f40 /api/src/glfs.c | |
parent | 5acb74d7daee0fc5c501a82e604ec2abdb3cf88a (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.c')
-rw-r--r-- | api/src/glfs.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c index 9b8cd4f2d2f..8ae3af61edb 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -1602,6 +1602,7 @@ pub_glfs_sysrq (struct glfs *fs, char sysrq) { glusterfs_ctx_t *ctx = NULL; int ret = 0; + int msg_len; char msg[1024] = {0,}; /* should not exceed 1024 chars */ if (!fs || !fs->ctx) { @@ -1618,8 +1619,9 @@ pub_glfs_sysrq (struct glfs *fs, char sysrq) struct glfs_sysrq_help *usage = NULL; for (usage = glfs_sysrq_help; usage->sysrq; usage++) { - snprintf (msg + strlen (msg), /* append to msg */ - sizeof (msg) - strlen (msg) - 2, + msg_len = strlen(msg); + snprintf (msg + msg_len, /* append to msg */ + sizeof (msg) - msg_len - 2, /* - 2 for the " " + terminating \0 */ " %s", usage->msg); } |