From 8a7e53b9a6a909b741f35b029d4feafd69b5b14b Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 11 Jul 2006 22:03:48 +0000 Subject: [PATCH] [SIGAR-9] Fix possible overflow in solaris sigar_mem_get impl --- ChangeLog | 2 ++ src/os/solaris/solaris_sigar.c | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ce8afd8..a3fcfd1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * Port linux impl to ppc64 arch + * [SIGAR-9] Fix possible overflow in solaris sigar_mem_get impl + 2006-07-10 Doug MacEachern * [SIGAR-4] Implement native sigar_net_stat_get and use w/ Java diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index 1babca5a..cfc3692a 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -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) { kstat_ctl_t *kc = sigar->kc; @@ -173,7 +170,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) SIGAR_ZERO(mem); /* 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); @@ -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) { 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; }