gfs2-utils: master - mkfs.gfs2: Terminate lockproto and locktable strings explicitly

Andrew Price andyp at fedoraproject.org
Mon Oct 6 18:54:09 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=1b27340e8afd3eea8d746c31ae461ce35145de36
Commit:        1b27340e8afd3eea8d746c31ae461ce35145de36
Parent:        bfd21b2144184a4cdf3628599152a5dbe1c3d0ab
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Mon Oct 6 14:22:16 2014 +0100
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Mon Oct 6 14:22:16 2014 +0100

mkfs.gfs2: Terminate lockproto and locktable strings explicitly

Although the length of the lockproto and locktable options are checked
in test_locking() already, coverity still complains about our use of
strcpy here, and it can't hurt to be a bit more defensive in our string
handling so switch to strncpy and terminate the strings explicitly.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/mkfs/main_mkfs.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e927d82..90ad4d9 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -966,8 +966,10 @@ void main_mkfs(int argc, char *argv[])
 	build_root(&sbd);
 	sb.sb_root_dir = sbd.md.rooti->i_di.di_num;
 
-	strcpy(sb.sb_lockproto, opts.lockproto);
-	strcpy(sb.sb_locktable, opts.locktable);
+	strncpy(sb.sb_lockproto, opts.lockproto, GFS2_LOCKNAME_LEN);
+	strncpy(sb.sb_locktable, opts.locktable, GFS2_LOCKNAME_LEN);
+	sb.sb_lockproto[GFS2_LOCKNAME_LEN - 1] = '\0';
+	sb.sb_locktable[GFS2_LOCKNAME_LEN - 1] = '\0';
 
 	do_init_inum(&sbd);
 	do_init_statfs(&sbd);


More information about the cluster-commits mailing list