diff options
author | N Balachandran <nbalacha@redhat.com> | 2018-09-07 11:39:39 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-09-12 06:25:31 +0000 |
commit | 65db3e596e456e11f524160261bf87a9ebe9fa00 (patch) | |
tree | 93eb1a2376c40136650000faae31b8a77a19af66 | |
parent | 763eb83dcbaf6a319fc2346fc696ab079e425ee3 (diff) |
dht: Use snprintf instead of strncpy
The recent changes to use malloc instead
of calloc left the new_name and new_path
non-null terminated. We now use snprintf
instead of strncpy to fix this.
Change-Id: I1a31701ca9447efde38921be0ba2c73cde2e7976
fixes: bz#1626346
Signed-off-by: N Balachandran <nbalacha@redhat.com>
-rw-r--r-- | xlators/cluster/dht/src/dht-helper.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/xlators/cluster/dht/src/dht-helper.c b/xlators/cluster/dht/src/dht-helper.c index 8bd3f564221..403f0a0f514 100644 --- a/xlators/cluster/dht/src/dht-helper.c +++ b/xlators/cluster/dht/src/dht-helper.c @@ -612,6 +612,14 @@ dht_frame_return (call_frame_t *frame) return this_call_cnt; } +/* + * Use this function to specify which subvol you want the file created + * on - this need not be the hashed subvol. + * Format: <filename>@<this->name>:<subvol-name> + * Eg: file-1@vol1-dht:vol1-client-0 + * where vol1 is a pure distribute volume + * will create file-1 on vol1-client-0 + */ int dht_filter_loc_subvol_key (xlator_t *this, loc_t *loc, loc_t *new_loc, @@ -634,24 +642,27 @@ dht_filter_loc_subvol_key (xlator_t *this, loc_t *loc, loc_t *new_loc, trav = this->children; while (trav) { - keylen = snprintf (key, sizeof (key), "*@%s:%s", this->name, trav->xlator->name); + keylen = snprintf (key, sizeof (key), "*@%s:%s", this->name, + trav->xlator->name); + /* Ignore '*' */ + keylen = keylen - 1; if (fnmatch (key, loc->name, FNM_NOESCAPE) == 0) { - name_len = strlen (loc->name); - new_name = GF_MALLOC(name_len, + name_len = strlen (loc->name) - keylen; + new_name = GF_MALLOC(name_len + 1, gf_common_mt_char); if (!new_name) goto out; if (fnmatch (key, loc->path, FNM_NOESCAPE) == 0) { - path_len = strlen (loc->path); - new_path = GF_MALLOC(path_len, + path_len = strlen (loc->path) - keylen; + new_path = GF_MALLOC(path_len + 1, gf_common_mt_char); if (!new_path) goto out; - strncpy (new_path, loc->path, (path_len - - keylen + 1)); + snprintf (new_path, path_len + 1, + "%s", loc->path); } - strncpy (new_name, loc->name, (name_len - - keylen + 1)); + snprintf (new_name, name_len + 1, "%s", + loc->name); if (new_loc) { new_loc->path = ((new_path) ? new_path: |