summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-volgen.c
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-21 20:41:20 +0300
committerAtin Mukherjee <amukherj@redhat.com>2018-09-07 16:17:18 +0000
commita880d6f6aa7a2979df8aa32b58f716ef0c578d3f (patch)
treebb95d28a14afc944c3755e612c05a44ca97a4979 /xlators/mgmt/glusterd/src/glusterd-volgen.c
parentdf697c68f6e1d676ae101e18b19f69e7241dc84a (diff)
multiple xlators (mgmt): strncpy()->sprintf(), reduce strlen()'s
xlators/mgmt/glusterd/src/glusterd-geo-rep.c xlators/mgmt/glusterd/src/glusterd-handshake.c xlators/mgmt/glusterd/src/glusterd-sm.c xlators/mgmt/glusterd/src/glusterd-store.c xlators/mgmt/glusterd/src/glusterd-utils.c xlators/mgmt/glusterd/src/glusterd-volgen.c xlators/mgmt/glusterd/src/glusterd-volume-ops.c xlators/mgmt/glusterd/src/glusterd.c 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(). Try to ensure output is not truncated. 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: Ib5d001857236f43e41c4a51b5f48e1a33110aaeb updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 35e49bf..33e6dc0 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -4073,8 +4073,11 @@ build_distribute:
goto out;
}
if (volinfo->tier_info.hot_brick_count) {
- strncpy (tmp_volname, volinfo->volname,
- GD_VOLUME_NAME_MAX - 1);
+ if (snprintf (tmp_volname, GD_VOLUME_NAME_MAX_TIER, "%s",
+ volinfo->volname) >= GD_VOLUME_NAME_MAX_TIER) {
+ ret = -1;
+ goto out;
+ }
if (volinfo->tier_info.cur_tier_hot)
strcat (volinfo->volname, "-hot");
else
@@ -4490,12 +4493,12 @@ client_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
goto out;
} else {
gfproxy_clnt = _gf_true;
- namelen = strlen (volinfo->volname) + strlen ("gfproxyd-") + 1;
+ namelen = strlen (volinfo->volname) + SLEN ("gfproxyd-") + 1;
subvol = alloca (namelen);
snprintf (subvol, namelen, "gfproxyd-%s", volinfo->volname);
namelen = strlen (volinfo->volname) +
- strlen ("-gfproxy-client") + 1;
+ SLEN ("-gfproxy-client") + 1;
xl_id = alloca (namelen);
snprintf (xl_id, namelen, "%s-gfproxy-client",
volinfo->volname);
@@ -6448,7 +6451,7 @@ build_bitd_volume_graph (volgen_graph_t *graph,
goto out;
get_transport_type (volinfo, set_dict, transt, _gf_false);
- if (!strncmp (transt, "tcp,rdma", strlen ("tcp,rdma")))
+ if (!strncmp (transt, "tcp,rdma", SLEN ("tcp,rdma")))
strncpy (transt, "tcp", sizeof(transt));
cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
@@ -6610,7 +6613,7 @@ build_scrub_volume_graph (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
goto out;
get_transport_type (volinfo, set_dict, transt, _gf_false);
- if (!strncmp (transt, "tcp,rdma", strlen ("tcp,rdma")))
+ if (!strncmp (transt, "tcp,rdma", SLEN ("tcp,rdma")))
strncpy (transt, "tcp", sizeof(transt));
cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {