diff --git a/CHANGES b/CHANGES index 249726cd8f..e53ff23d07 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +5506. [bug] Properly handle failed sysconf() calls, so we don't + report invalid memory size. [GL #2166] + 5505. [bug] Updating contents of a mixed-case RPZ could cause some rules to be ignored. [GL #2169] diff --git a/doc/notes/notes-current.rst b/doc/notes/notes-current.rst index 4fccc02611..8969bd5252 100644 --- a/doc/notes/notes-current.rst +++ b/doc/notes/notes-current.rst @@ -42,3 +42,7 @@ Bug Fixes - Updating contents of an RPZ zone which contained names spelled using varying letter case could cause some processing rules in that RPZ zone to be erroneously ignored. [GL #2169] + +- `named` would report invalid memory size when running in an environment + that doesn't properly report number of available memory pages or pagesize. + [GL #2166] diff --git a/lib/isc/unix/meminfo.c b/lib/isc/unix/meminfo.c index 04b01ce177..46cb7d6855 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); }