Use snprintf instead of sprintf.

MFC after:	2 weeks
This commit is contained in:
Xin LI 2020-07-26 01:45:26 +00:00
parent 795c5f365e
commit 7201590bbf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363540
3 changed files with 8 additions and 6 deletions

View File

@ -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);

View File

@ -224,7 +224,8 @@ g_part_vtoc8_create(struct g_part_table *basetable, struct g_part_parms *gpp)
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, struct g_provider *pp)
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);

View File

@ -227,7 +227,7 @@ virstor_ctl_stop(struct gctl_req *req, struct g_class *cp)
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_class *cp)
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);