svn commit: r342823 - head/contrib/xz/src/common
Konstantin Belousov
kib at FreeBSD.org
Sun Jan 6 23:59:05 UTC 2019
Author: kib
Date: Sun Jan 6 23:59:04 2019
New Revision: 342823
URL: https://svnweb.freebsd.org/changeset/base/342823
Log:
Clamp tuklib_physmem() return value to SIZE_T_MAX.
On 32bit platforms it is possible to have (much) more physical RAM
than is mappable into single address space. In this case liblzma
scales the value into a request to mmap more address space than it is
theoretically possible.
Reported and tested by: pho
Reviewed by: delphij
Discussed with: emaste
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Modified:
head/contrib/xz/src/common/tuklib_physmem.c
Modified: head/contrib/xz/src/common/tuklib_physmem.c
==============================================================================
--- head/contrib/xz/src/common/tuklib_physmem.c Sun Jan 6 23:43:12 2019 (r342822)
+++ head/contrib/xz/src/common/tuklib_physmem.c Sun Jan 6 23:59:04 2019 (r342823)
@@ -45,6 +45,7 @@
# include <sys/systemcfg.h>
#elif defined(TUKLIB_PHYSMEM_SYSCONF)
+# include <limits.h>
# include <unistd.h>
#elif defined(TUKLIB_PHYSMEM_SYSCTL)
@@ -145,13 +146,16 @@ tuklib_physmem(void)
#elif defined(TUKLIB_PHYSMEM_SYSCONF)
const long pagesize = sysconf(_SC_PAGESIZE);
const long pages = sysconf(_SC_PHYS_PAGES);
- if (pagesize != -1 && pages != -1)
+ if (pagesize != -1 && pages != -1) {
// According to docs, pagesize * pages can overflow.
// Simple case is 32-bit box with 4 GiB or more RAM,
// which may report exactly 4 GiB of RAM, and "long"
// being 32-bit will overflow. Casting to uint64_t
// hopefully avoids overflows in the near future.
ret = (uint64_t)pagesize * (uint64_t)pages;
+ if (ret > SIZE_T_MAX)
+ ret = SIZE_T_MAX;
+ }
#elif defined(TUKLIB_PHYSMEM_SYSCTL)
int name[2] = {
More information about the svn-src-all
mailing list