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.

(cherry picked from commit 79ca724d46)
This commit is contained in:
Ondřej Surý
2020-09-21 10:59:36 +02:00
parent f12893d4a7
commit 98def35e72
+9 -2
View 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);
}