diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-01-06 08:57:31 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-01-06 08:57:31 +0000 |
commit | ddad69e070767000c90b960a838efedffaa8eb7f (patch) | |
tree | d863275779815a5218f33ab1003b8cfa0efbf954 | |
parent | 33a27cb5468e9be1c8a078b172ec934b2710885f (diff) |
validate mfs size to avoid wrapping. ok miod@
-rw-r--r-- | sbin/newfs/mkfs.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index e965a1ee976..7d53f37709e 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs.c,v 1.45 2004/10/14 07:40:29 otto Exp $ */ +/* $OpenBSD: mkfs.c,v 1.46 2005/01/06 08:57:30 otto 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.45 2004/10/14 07:40:29 otto Exp $"; +static char rcsid[] = "$OpenBSD: mkfs.c,v 1.46 2005/01/06 08:57:30 otto Exp $"; #endif #endif /* not lint */ @@ -183,11 +183,16 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, time(&utime); #endif if (mfs) { - membase = mmap(NULL, fssize * sectorsize, PROT_READ|PROT_WRITE, + quad_t sz = (quad_t)fssize * sectorsize; + if (sz > SIZE_T_MAX) { + errno = ENOMEM; + err(12, "mmap"); + } + membase = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0); if (membase == MAP_FAILED) err(12, "mmap"); - madvise(membase, fssize * sectorsize, MADV_RANDOM); + madvise(membase, sz, MADV_RANDOM); } fsi = fi; fso = fo; |