From: Ondřej Surý Date: Thu, 17 Sep 2020 12:37:24 +0000 (+0200) Subject: Handle the errors from sysconf() call in isc_meminfo_totalphys() X-Git-Tag: v9.17.6~48^2~1 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=79ca724d46918387fba6b2dc484d67390bcbbd56;p=thirdparty%2Fbind9.git Handle the errors from sysconf() call in isc_meminfo_totalphys() isc_meminfo_totalphys() would return invalid memory size when sysconf() call would fail, because ((size_t)-1 * -1) is very large number. --- diff --git a/lib/isc/unix/meminfo.c b/lib/isc/unix/meminfo.c index 04b01ce177c..46cb7d68550 100644 --- a/lib/isc/unix/meminfo.c +++ b/lib/isc/unix/meminfo.c @@ -35,7 +35,14 @@ isc_meminfo_totalphys(void) { #endif /* if defined(CTL_HW) && (defined(HW_PHYSMEM64) || defined(HW_MEMSIZE)) \ * */ #if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) - return ((size_t)(sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE))); + long pages = sysconf(_SC_PHYS_PAGES); + long pagesize = sysconf(_SC_PAGESIZE); + + if (pages == -1 || pagesize == -1) { + return (0); + } + + return ((size_t)pages * pagesize); #endif /* if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) */ return (0); }