diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-21 20:43:07 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 13:13:43 +0000 |
commit | 052849983e51a061d7fb2c3ffd74fa78bb257084 (patch) | |
tree | 5f82954bd3518c7eeab6ece16edbf72b0a3e0db1 /libglusterfs/src/store.c | |
parent | 67cfacaa9d5ce31240a4d39e81b2984a57ac8865 (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 'libglusterfs/src/store.c')
-rw-r--r-- | libglusterfs/src/store.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c index 15a888d36c0..5172982149f 100644 --- a/libglusterfs/src/store.c +++ b/libglusterfs/src/store.c @@ -491,8 +491,10 @@ gf_store_iter_new (gf_store_handle_t *shandle, gf_store_iter_t **iter) if (!tmp_iter) goto out; - strncpy (tmp_iter->filepath, shandle->path, sizeof (tmp_iter->filepath)); - tmp_iter->filepath[sizeof (tmp_iter->filepath) - 1] = 0; + if (snprintf (tmp_iter->filepath, sizeof (tmp_iter->filepath), "%s", + shandle->path) >= sizeof (tmp_iter->filepath)) + goto out; + tmp_iter->file = fp; *iter = tmp_iter; |