summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-04-14 19:58:33 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-04-14 19:58:33 +0000
commitfba6017a3ba91f96a647a2f5378b9c9508b860f9 (patch)
tree95caf22dd47b029d032b535133a378bee41c7e3e /sbin
parent4d82c075e7b63f837e4c1533db43dab3ce29467a (diff)
handle snprintf out of range conditions; otto ok
Diffstat (limited to 'sbin')
-rw-r--r--sbin/growfs/growfs.c8
-rw-r--r--sbin/newfs/mkfs.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c
index 9b55b8e72b2..73ac3549050 100644
--- a/sbin/growfs/growfs.c
+++ b/sbin/growfs/growfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: growfs.c,v 1.11 2004/03/15 08:52:01 deraadt Exp $ */
+/* $OpenBSD: growfs.c,v 1.12 2005/04/14 19:58:32 deraadt Exp $ */
/*
* Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz
* Copyright (c) 1980, 1989, 1993 The Regents of the University of California.
@@ -46,7 +46,7 @@ static const char copyright[] =
Copyright (c) 1980, 1989, 1993 The Regents of the University of California.\n\
All rights reserved.\n";
-static const char rcsid[] = "$OpenBSD: growfs.c,v 1.11 2004/03/15 08:52:01 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: growfs.c,v 1.12 2005/04/14 19:58:32 deraadt Exp $";
#endif /* not lint */
/* ********************************************************** INCLUDES ***** */
@@ -236,7 +236,9 @@ growfs(int fsi, int fso, unsigned int Nflag)
j = snprintf(tmpbuf, sizeof tmpbuf, " %d%s",
(int)fsbtodb(&sblock, cgsblock(&sblock, cylno)),
cylno < (sblock.fs_ncg - 1) ? "," : "");
- if (i + j >= width) {
+ if (j >= sizeof tmpbuf)
+ j = sizeof tmpbuf - 1;
+ if (j == -1 || i + j >= width) {
printf("\n");
i = 0;
}
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index 7d53f37709e..b62854e6824 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkfs.c,v 1.46 2005/01/06 08:57:30 otto Exp $ */
+/* $OpenBSD: mkfs.c,v 1.47 2005/04/14 19:58:32 deraadt Exp $ */
/* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94";
#else
-static char rcsid[] = "$OpenBSD: mkfs.c,v 1.46 2005/01/06 08:57:30 otto Exp $";
+static char rcsid[] = "$OpenBSD: mkfs.c,v 1.47 2005/04/14 19:58:32 deraadt Exp $";
#endif
#endif /* not lint */
@@ -665,7 +665,9 @@ next:
continue;
j = snprintf(tmpbuf, sizeof tmpbuf, " %ld,",
fsbtodb(&sblock, cgsblock(&sblock, cylno)));
- if (i+j >= width) {
+ if (j >= sizeof tmpbuf)
+ j = sizeof tmpbuf - 1;
+ if (j == -1 || i+j >= width) {
printf("\n");
i = 0;
}