From fba6017a3ba91f96a647a2f5378b9c9508b860f9 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Thu, 14 Apr 2005 19:58:33 +0000 Subject: handle snprintf out of range conditions; otto ok --- sbin/newfs/mkfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sbin/newfs') 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; } -- cgit v1.2.3