aboutsummaryrefslogtreecommitdiff
path: root/contrib/xz
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2019-01-06 23:59:04 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2019-01-06 23:59:04 +0000
commit866fe991ac4014aafb031f2651f52444e2fdf3c5 (patch)
tree4ec056647af07655cde3836a3cff930a19f09a7e /contrib/xz
parent9f0bfc517ca9f5b929eb7125d0da53f6705e6e2f (diff)
downloadsrc-866fe991ac4014aafb031f2651f52444e2fdf3c5.tar.gz
src-866fe991ac4014aafb031f2651f52444e2fdf3c5.zip
Notes
Diffstat (limited to 'contrib/xz')
-rw-r--r--contrib/xz/src/common/tuklib_physmem.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/contrib/xz/src/common/tuklib_physmem.c b/contrib/xz/src/common/tuklib_physmem.c
index 4053ad006a64..01f6d1779510 100644
--- a/contrib/xz/src/common/tuklib_physmem.c
+++ b/contrib/xz/src/common/tuklib_physmem.c
@@ -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] = {