From 79ca724d46918387fba6b2dc484d67390bcbbd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 17 Sep 2020 14:37:24 +0200 Subject: [PATCH 1/2] 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. --- lib/isc/unix/meminfo.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); } From 2869ca1401a45d610354e81e6773d4666001a974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 17 Sep 2020 14:47:16 +0200 Subject: [PATCH 2/2] Add CHANGES and release note for GL #2166 --- CHANGES | 3 +++ doc/notes/notes-current.rst | 4 ++++ 2 files changed, 7 insertions(+) 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]