[SIGAR-9] Fix possible overflow in solaris sigar_mem_get impl

This commit is contained in:
Doug MacEachern 2006-07-11 22:03:48 +00:00
parent d03d4a94d2
commit 8a7e53b9a6
2 changed files with 6 additions and 5 deletions

View File

@ -2,6 +2,8 @@
* Port linux impl to ppc64 arch * Port linux impl to ppc64 arch
* [SIGAR-9] Fix possible overflow in solaris sigar_mem_get impl
2006-07-10 Doug MacEachern <dougm@hyperic.com> 2006-07-10 Doug MacEachern <dougm@hyperic.com>
* [SIGAR-4] Implement native sigar_net_stat_get and use w/ Java * [SIGAR-4] Implement native sigar_net_stat_get and use w/ Java

View File

@ -162,9 +162,6 @@ char *sigar_os_error_string(sigar_t *sigar, int err)
} }
} }
#define KPAGE_SHIFT(v) \
((v) << sigar->pagesize)
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
{ {
kstat_ctl_t *kc = sigar->kc; kstat_ctl_t *kc = sigar->kc;
@ -173,7 +170,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
SIGAR_ZERO(mem); SIGAR_ZERO(mem);
/* XXX: is mem hot swappable or can we just do this during open ? */ /* XXX: is mem hot swappable or can we just do this during open ? */
mem->total = KPAGE_SHIFT((sigar_uint64_t)sysconf(_SC_PHYS_PAGES)); mem->total = sysconf(_SC_PHYS_PAGES);
mem->total <<= sigar->pagesize;
sigar_mem_calc_ram(sigar, mem); sigar_mem_calc_ram(sigar, mem);
@ -184,7 +182,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
if ((ksp = sigar->ks.syspages) && kstat_read(kc, ksp, NULL) >= 0) { if ((ksp = sigar->ks.syspages) && kstat_read(kc, ksp, NULL) >= 0) {
sigar_koffsets_init_syspages(sigar, ksp); sigar_koffsets_init_syspages(sigar, ksp);
mem->free = KPAGE_SHIFT(kSYSPAGES(KSTAT_SYSPAGES_FREE)); mem->free = kSYSPAGES(KSTAT_SYSPAGES_FREE);
mem->free <<= sigar->pagesize;
mem->used = mem->total - mem->free; mem->used = mem->total - mem->free;
} }