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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user