summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-lib/src/rpc-clnt.c
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-21 20:43:07 +0300
committerAmar Tumballi <amarts@redhat.com>2018-08-31 13:13:43 +0000
commit052849983e51a061d7fb2c3ffd74fa78bb257084 (patch)
tree5f82954bd3518c7eeab6ece16edbf72b0a3e0db1 /rpc/rpc-lib/src/rpc-clnt.c
parent67cfacaa9d5ce31240a4d39e81b2984a57ac8865 (diff)
Various files: 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(). Check for truncated output where applicable. Also: - save the result of strlen() and re-use it when possible. - move from strlen to SLEN (sizeof() ) for const strings. Compile-tested only! Change-Id: I54e80d4f4a80e98d3775e376efe05c51af0b29eb updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'rpc/rpc-lib/src/rpc-clnt.c')
-rw-r--r--rpc/rpc-lib/src/rpc-clnt.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
index 5e1d41311d0..a4663648a38 100644
--- a/rpc/rpc-lib/src/rpc-clnt.c
+++ b/rpc/rpc-lib/src/rpc-clnt.c
@@ -106,6 +106,7 @@ call_bail (void *data)
struct timespec timeout = {0,};
char peerid[UNIX_PATH_MAX] = {0};
gf_boolean_t need_unref = _gf_false;
+ int len;
GF_VALIDATE_OR_GOTO ("client", data, out);
@@ -169,8 +170,8 @@ call_bail (void *data)
list_for_each_entry_safe (trav, tmp, &list, list) {
gf_time_fmt (frame_sent, sizeof frame_sent,
trav->saved_at.tv_sec, gf_timefmt_FT);
- snprintf (frame_sent + strlen (frame_sent),
- 256 - strlen (frame_sent),
+ len = strlen (frame_sent);
+ snprintf (frame_sent + len, sizeof (frame_sent) - len,
".%"GF_PRI_SUSECONDS, trav->saved_at.tv_usec);
gf_log (conn->name, GF_LOG_ERROR,
@@ -324,14 +325,15 @@ saved_frames_unwind (struct saved_frames *saved_frames)
struct saved_frame *trav = NULL;
struct saved_frame *tmp = NULL;
char timestr[1024] = {0,};
+ int len;
list_splice_init (&saved_frames->lk_sf.list, &saved_frames->sf.list);
list_for_each_entry_safe (trav, tmp, &saved_frames->sf.list, list) {
gf_time_fmt (timestr, sizeof timestr,
trav->saved_at.tv_sec, gf_timefmt_FT);
- snprintf (timestr + strlen (timestr),
- sizeof(timestr) - strlen (timestr),
+ len = strlen (timestr);
+ snprintf (timestr + len, sizeof(timestr) - len,
".%"GF_PRI_SUSECONDS, trav->saved_at.tv_usec);
if (!trav->rpcreq || !trav->rpcreq->prog)