From cb9ef1cfbd0a98983fce921f4ae023e577b9e16b Mon Sep 17 00:00:00 2001 From: chs Date: Thu, 12 Apr 2007 05:19:18 +0000 Subject: [PATCH] apply revision 1.31 yet again: "make sure that we don't try to allocate negative memory when blks == 0." or on amd64, "make sure that we don't allocate 32 GB when blks == 0." --- sbin/fsck_ffs/inode.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 11afd36b030b..5c473ad70426 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -1,4 +1,4 @@ -/* $NetBSD: inode.c,v 1.57 2006/04/21 15:00:49 skrll Exp $ */ +/* $NetBSD: inode.c,v 1.58 2007/04/12 05:19:18 chs Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: inode.c,v 1.57 2006/04/21 15:00:49 skrll Exp $"); +__RCSID("$NetBSD: inode.c,v 1.58 2007/04/12 05:19:18 chs Exp $"); #endif #endif /* not lint */ @@ -477,7 +477,7 @@ cacheino(union dinode *dp, ino_t inumber) { struct inoinfo *inp; struct inoinfo **inpp, **ninpsort; - unsigned int blks; + unsigned int blks, extra; int i; int64_t size; @@ -485,9 +485,11 @@ cacheino(union dinode *dp, ino_t inumber) blks = howmany(size, sblock->fs_bsize); if (blks > NDADDR) blks = NDADDR + NIADDR; - - inp = (struct inoinfo *) malloc(sizeof(*inp) + (blks - 1) - * sizeof (int64_t)); + if (blks > 0) + extra = (blks - 1) * sizeof (int64_t); + else + extra = 0; + inp = malloc(sizeof(*inp) + extra); if (inp == NULL) return; inpp = &inphead[inumber % dirhash];