diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-21 19:20:25 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 01:36:34 +0000 |
commit | 4b5e3c347cfb80e4749f1963e25d1dd93563f784 (patch) | |
tree | f82b1948aec0110f46d3c1e2b230c6971871f413 /xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c | |
parent | 4996a229f3d09cbb6ed3b9dcdf1d527f36803919 (diff) | |
download | glusterfs-4b5e3c347cfb80e4749f1963e25d1dd93563f784.tar.gz glusterfs-4b5e3c347cfb80e4749f1963e25d1dd93563f784.tar.xz glusterfs-4b5e3c347cfb80e4749f1963e25d1dd93563f784.zip |
bit-rot xlator: strncpy()->sprintf(), reduce strlen()'s
xlators/features/bit-rot/src/bitd/bit-rot-scrub-status.c
xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c
xlators/features/bit-rot/src/stub/bit-rot-stub.c
xlators/features/bit-rot/src/stub/bit-rot-stub.h
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(). Ensure sprintf() results do not
truncate.
Also:
- save the result of strlen() and re-use it when possible.
- move from strlen to SLEN or sizeof() for const strings.
- move ret from int32 to int.
Compile-tested only!
Change-Id: Ib9b923c45d2d59ac15a105410e8160b252061018
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c')
-rw-r--r-- | xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c b/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c index cc1a6e9a66..42398bbf2c 100644 --- a/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c +++ b/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c @@ -257,10 +257,14 @@ br_stub_dir_create (xlator_t *this, br_stub_private_t *priv) gf_uuid_copy (priv->bad_object_dir_gfid, BR_BAD_OBJ_CONTAINER); - strncpy (fullpath, priv->stub_basepath, sizeof (fullpath)); + if (snprintf (fullpath, sizeof (fullpath), "%s", + priv->stub_basepath) >= sizeof (fullpath)) + goto out; - snprintf (stub_gfid_path, sizeof (stub_gfid_path), "%s/stub-%s", - priv->stub_basepath, uuid_utoa (priv->bad_object_dir_gfid)); + if (snprintf (stub_gfid_path, sizeof (stub_gfid_path), "%s/stub-%s", + priv->stub_basepath, uuid_utoa (priv->bad_object_dir_gfid)) + >= sizeof (stub_gfid_path)) + goto out; ret = br_stub_check_stub_directory (this, fullpath); if (ret) |