diff options
author | Kaleb S. KEITHLE <kkeithle@redhat.com> | 2018-11-09 09:45:05 -0500 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-11-15 05:06:59 +0000 |
commit | 4a4ba1f2eb0be2da9e88560246730af87788295f (patch) | |
tree | bc0a3bc043e012efc60dc58e131abb47c50ce979 /xlators/mgmt/glusterd/src/glusterd-volgen.c | |
parent | 76906af9d70fc784de728a70e3dbda62dece5e10 (diff) |
core: fix strncpy warnings
Since gcc-8.2.x (fedora-28 or so) gcc has been emitting warnings
about buggy use of strncpy.
Most uses that gcc warns about in our sources are exactly backwards;
the 'limit' or len is the strlen/size of the _source param_, giving
exactly zero protection against overruns. (Which was, after all, one
of the points of using strncpy in the first place.)
IOW, many warnings are about uses that look approximately like this:
...
char dest[8];
char src[] = "this is a string longer than eight chars";
...
strncpy (dest, src, sizeof(src)); /* boom */
...
The len/limit should be sizeof(dest).
Note: the above example has a definite over-run. In our source the
overrun is typically only theoretical (but possibly exploitable.)
Also strncpy doesn't null-terminate on truncation; snprintf does; prefer
snprintf over strncpy.
Mildly surprising that coverity doesn't warn/isn't warning about this.
Change-Id: I022d5c6346a751e181ad44d9a099531c1172626e
updates: bz#1193929
Signed-off-by: Kaleb S. KEITHLE <kkeithle@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 9a6623c2bd0..49542328916 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -5407,7 +5407,7 @@ glusterd_is_valid_volfpath(char *volname, char *brick) ret = 0; goto out; } - strncpy(volinfo->volname, volname, strlen(volname)); + (void)snprintf(volinfo->volname, sizeof(volinfo->volname), "%s", volname); get_brick_filepath(volfpath, volinfo, brickinfo, NULL); ret = ((strlen(volfpath) < PATH_MAX) && @@ -6149,7 +6149,7 @@ build_bitd_volume_graph(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, get_transport_type(volinfo, set_dict, transt, _gf_false); if (!strncmp(transt, "tcp,rdma", SLEN("tcp,rdma"))) - strncpy(transt, "tcp", sizeof(transt)); + (void)snprintf(transt, sizeof(transt), "%s", "tcp"); cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) { @@ -6308,7 +6308,7 @@ build_scrub_volume_graph(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, get_transport_type(volinfo, set_dict, transt, _gf_false); if (!strncmp(transt, "tcp,rdma", SLEN("tcp,rdma"))) - strncpy(transt, "tcp", sizeof(transt)); + (void)snprintf(transt, sizeof(transt), "%s", "tcp"); cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) { |