]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Handle the errors from sysconf() call in isc_meminfo_totalphys()
authorOndřej Surý <ondrej@sury.org>
Thu, 17 Sep 2020 12:37:24 +0000 (14:37 +0200)
committerOndřej Surý <ondrej@sury.org>
Mon, 21 Sep 2020 08:59:36 +0000 (10:59 +0200)
isc_meminfo_totalphys() would return invalid memory size when sysconf()
call would fail, because ((size_t)-1 * -1) is very large number.

(cherry picked from commit 79ca724d46918387fba6b2dc484d67390bcbbd56)

lib/isc/unix/meminfo.c

index 634528b23db2acaea4eff6215c97a43272c1e021..1620aa428c5b1d32622bc54d5c7c0e5826b661db 100644 (file)
@@ -34,7 +34,14 @@ isc_meminfo_totalphys(void) {
                return (size);
 #endif
 #if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
-       return ((size_t) (sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE)));
-#endif
+       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);
 }