range-check what we assign to int cachebufs from calculations with

uint64_t usermem. This only becomes relevant if you have several TB of RAM.
Promoting cachebufs to uint64_t is not necessary as it gets limited to
(currently) 512 anyway.

fixes the last issue of PR: 19852
This commit is contained in:
spz 2010-01-27 12:20:25 +00:00
parent 296908ed7b
commit 1cb24f3feb
1 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rcache.c,v 1.22 2008/04/28 20:23:08 martin Exp $ */ /* $NetBSD: rcache.c,v 1.23 2010/01/27 12:20:25 spz Exp $ */
/*- /*-
* Copyright (c) 1999 The NetBSD Foundation, Inc. * Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: rcache.c,v 1.22 2008/04/28 20:23:08 martin Exp $"); __RCSID("$NetBSD: rcache.c,v 1.23 2010/01/27 12:20:25 spz Exp $");
#endif /* not lint */ #endif /* not lint */
#include <sys/types.h> #include <sys/types.h>
@ -106,7 +106,7 @@ initcache(int cachesize, int readblksize)
nblksread <<= ufsib->ufs_bshift - dev_bshift; nblksread <<= ufsib->ufs_bshift - dev_bshift;
if (cachesize == -1) { /* Compute from memory available */ if (cachesize == -1) { /* Compute from memory available */
uint64_t usermem; uint64_t usermem, cachetmp;
int mib[2] = { CTL_HW, HW_USERMEM64 }; int mib[2] = { CTL_HW, HW_USERMEM64 };
len = sizeof(usermem); len = sizeof(usermem);
@ -115,7 +115,9 @@ initcache(int cachesize, int readblksize)
strerror(errno)); strerror(errno));
return; return;
} }
cachebufs = (usermem / MAXMEMPART) / CSIZE; cachetmp = (usermem / MAXMEMPART) / CSIZE;
/* for those with TB of RAM */
cachebufs = (cachetmp > INT_MAX) ? INT_MAX : cachetmp;
} else { /* User specified */ } else { /* User specified */
cachebufs = cachesize; cachebufs = cachesize;
} }