diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-21 19:25:11 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 06:16:12 +0000 |
commit | a1d61242baed1c2078707c401632719e756fcacb (patch) | |
tree | 7d121bbd7ee51db8fca493e94a9b9a4d4521b377 /xlators/features/changetimerecorder/src/ctr-helper.h | |
parent | 7772315bd7d82d5f06f008dfe767f1e597a41b23 (diff) | |
download | glusterfs-a1d61242baed1c2078707c401632719e756fcacb.tar.gz glusterfs-a1d61242baed1c2078707c401632719e756fcacb.tar.xz glusterfs-a1d61242baed1c2078707c401632719e756fcacb.zip |
changetimerecoder xlator: strncpy()->sprintf(), reduce strlen()'s
xlators/features/changetimerecorder/src/changetimerecorder.c
xlators/features/changetimerecorder/src/ctr-helper.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(). Check for output truncation
where applicable.
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: I2dd5629183222da8c9251af43b8b29aacf12a20a
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/features/changetimerecorder/src/ctr-helper.h')
-rw-r--r-- | xlators/features/changetimerecorder/src/ctr-helper.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/xlators/features/changetimerecorder/src/ctr-helper.h b/xlators/features/changetimerecorder/src/ctr-helper.h index f450611505..f821201d3a 100644 --- a/xlators/features/changetimerecorder/src/ctr-helper.h +++ b/xlators/features/changetimerecorder/src/ctr-helper.h @@ -641,15 +641,17 @@ ctr_delete_hard_link_from_db (xlator_t *this, /* Set gfdb_db_record to 0 */ memset (&gfdb_db_record, 0, sizeof(gfdb_db_record)); + /* Copy basename */ + if (snprintf (gfdb_db_record.file_name, GF_NAME_MAX, "%s", + basename) >= GF_NAME_MAX) + goto out; + /* Copy gfid into db record */ gf_uuid_copy (gfdb_db_record.gfid, gfid); /* Copy pargid into db record */ gf_uuid_copy (gfdb_db_record.pargfid, pargfid); - /* Copy basename */ - strncpy (gfdb_db_record.file_name, basename, GF_NAME_MAX - 1); - gfdb_db_record.gfdb_fop_path = fop_path; gfdb_db_record.gfdb_fop_type = fop_type; |