diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-21 19:23:01 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 06:14:47 +0000 |
commit | dc6e6b71f87f6f89bb0b69816e92779595d716bd (patch) | |
tree | e9fbd7f4384a6ccb05a3537b064588ee30f1b6be /xlators/features/changelog/lib/src/gf-changelog.c | |
parent | 058d215174b93b3aa14be99073979f45642e519e (diff) |
changelog xlator: strncpy()->sprintf(), reduce strlen()'s
xlators/features/changelog/lib/src/gf-changelog-journal-handler.c
xlators/features/changelog/lib/src/gf-changelog.c
xlators/features/changelog/src/changelog-helpers.c
xlators/features/changelog/src/changelog-misc.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(). Where possible, ensure there's
no truncation of the output.
Also:
- save the result of strlen() and re-use it when possible.
- move from strlen to SLEN (sizeof() ) for const strings.
- switch a strncpy to a memcpy.
Compile-tested only!
Change-Id: Ia7a52bce0b243613ad910192ec163c93d944e077
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/features/changelog/lib/src/gf-changelog.c')
-rw-r--r-- | xlators/features/changelog/lib/src/gf-changelog.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog.c b/xlators/features/changelog/lib/src/gf-changelog.c index 6ad6c63740d..8198560e736 100644 --- a/xlators/features/changelog/lib/src/gf-changelog.c +++ b/xlators/features/changelog/lib/src/gf-changelog.c @@ -374,8 +374,9 @@ gf_setup_brick_connection (xlator_t *this, entry->connstate = GF_CHANGELOG_CONN_STATE_PENDING; entry->notify = brick->filter; - (void) strncpy (entry->brick, brick->brick_path, PATH_MAX-1); - entry->brick[PATH_MAX-1] = 0; + if (snprintf (entry->brick, PATH_MAX, "%s", brick->brick_path) + >= PATH_MAX) + goto free_entry; entry->this = this; entry->invokerxl = xl; |