Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Jul 2020 01:45:26 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r363540 - in head/sys/geom: . part virstor
Message-ID:  <202007260145.06Q1jQKX014154@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Sun Jul 26 01:45:26 2020
New Revision: 363540
URL: https://svnweb.freebsd.org/changeset/base/363540

Log:
  Use snprintf instead of sprintf.
  
  MFC after:	2 weeks

Modified:
  head/sys/geom/geom_ccd.c
  head/sys/geom/part/g_part_vtoc8.c
  head/sys/geom/virstor/g_virstor.c

Modified: head/sys/geom/geom_ccd.c
==============================================================================
--- head/sys/geom/geom_ccd.c	Sun Jul 26 01:11:30 2020	(r363539)
+++ head/sys/geom/geom_ccd.c	Sun Jul 26 01:45:26 2020	(r363540)
@@ -771,7 +771,7 @@ g_ccd_create(struct gctl_req *req, struct g_class *mp)
 
 	/* Check all providers are valid */
 	for (i = 0; i < *nprovider; i++) {
-		sprintf(buf, "provider%d", i);
+		snprintf(buf, sizeof(buf), "provider%d", i);
 		pp = gctl_get_provider(req, buf);
 		if (pp == NULL)
 			return;
@@ -788,7 +788,7 @@ g_ccd_create(struct gctl_req *req, struct g_class *mp)
 
 	/* Create consumers and attach to all providers */
 	for (i = 0; i < *nprovider; i++) {
-		sprintf(buf, "provider%d", i);
+		snprintf(buf, sizeof(buf), "provider%d", i);
 		pp = gctl_get_provider(req, buf);
 		cp = g_new_consumer(gp);
 		error = g_attach(cp, pp);

Modified: head/sys/geom/part/g_part_vtoc8.c
==============================================================================
--- head/sys/geom/part/g_part_vtoc8.c	Sun Jul 26 01:11:30 2020	(r363539)
+++ head/sys/geom/part/g_part_vtoc8.c	Sun Jul 26 01:45:26 2020	(r363540)
@@ -224,7 +224,8 @@ g_part_vtoc8_create(struct g_part_table *basetable, st
 	ncyls = pcyls - acyls;
 	msize = ncyls * table->secpercyl;
 
-	sprintf(table->vtoc.ascii, "FreeBSD%lldM cyl %u alt %u hd %u sec %u",
+	snprintf(table->vtoc.ascii, sizeof(table->vtoc.ascii),
+	    "FreeBSD%lldM cyl %u alt %u hd %u sec %u",
 	    (long long)(msize / 2048), ncyls, acyls, basetable->gpt_heads,
 	    basetable->gpt_sectors);
 	be32enc(&table->vtoc.version, VTOC_VERSION);
@@ -338,7 +339,8 @@ vtoc8_set_rawsize(struct g_part_table *basetable, stru
 	basetable->gpt_last = msize - 1;
 
 	bzero(table->vtoc.ascii, sizeof(table->vtoc.ascii));
-	sprintf(table->vtoc.ascii, "FreeBSD%lldM cyl %u alt %u hd %u sec %u",
+	snprintf(table->vtoc.ascii, sizeof(table->vtoc.ascii),
+	    "FreeBSD%lldM cyl %u alt %u hd %u sec %u",
 	    (long long)(msize / 2048), ncyls, acyls, basetable->gpt_heads,
 	    basetable->gpt_sectors);
 	be16enc(&table->vtoc.physcyls, pcyls);

Modified: head/sys/geom/virstor/g_virstor.c
==============================================================================
--- head/sys/geom/virstor/g_virstor.c	Sun Jul 26 01:11:30 2020	(r363539)
+++ head/sys/geom/virstor/g_virstor.c	Sun Jul 26 01:45:26 2020	(r363540)
@@ -227,7 +227,7 @@ virstor_ctl_stop(struct gctl_req *req, struct g_class 
 		struct g_virstor_softc *sc;
 		int error;
 
-		sprintf(param, "arg%d", i);
+		snprintf(param, sizeof(param), "arg%d", i);
 		name = gctl_get_asciiparam(req, param);
 		if (name == NULL) {
 			gctl_error(req, "No 'arg%d' argument", i);
@@ -565,7 +565,7 @@ virstor_ctl_remove(struct gctl_req *req, struct g_clas
 		int j, found;
 		struct g_virstor_component *newcomp, *compbak;
 
-		sprintf(param, "arg%d", i);
+		snprintf(param, sizeof(param), "arg%d", i);
 		prov_name = gctl_get_asciiparam(req, param);
 		if (prov_name == NULL) {
 			gctl_error(req, "Error fetching argument '%s'", param);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007260145.06Q1jQKX014154>