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/growfs/growfs.c | 8 +++++--- sbin/newfs/mkfs.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'sbin') 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; } -- cgit v1.2.3