Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Jan 2019 02:36:58 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r342986 - stable/12/contrib/xz/src/common
Message-ID:  <201901130236.x0D2awCp046939@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sun Jan 13 02:36:58 2019
New Revision: 342986
URL: https://svnweb.freebsd.org/changeset/base/342986

Log:
  MFC r342823:
  Clamp tuklib_physmem() return value to SIZE_T_MAX.

Modified:
  stable/12/contrib/xz/src/common/tuklib_physmem.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/contrib/xz/src/common/tuklib_physmem.c
==============================================================================
--- stable/12/contrib/xz/src/common/tuklib_physmem.c	Sun Jan 13 02:33:20 2019	(r342985)
+++ stable/12/contrib/xz/src/common/tuklib_physmem.c	Sun Jan 13 02:36:58 2019	(r342986)
@@ -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] = {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201901130236.x0D2awCp046939>