[SIGAR-85] Fix possible integer overflow in sigar_file_system_usage
This commit is contained in:
parent
96360a8b3e
commit
248f93c76e
|
@ -1500,11 +1500,6 @@ int sigar_file_system_list_get(sigar_t *sigar,
|
|||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
/* XXX this is exactly the same as linux and hpux, solaris is darn close */
|
||||
|
||||
#define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \
|
||||
(((sigar_uint64_t)buf.f * (buf.f_bsize / 512)) >> 1)
|
||||
|
||||
#define LSPV_CMD "/usr/sbin/lspv"
|
||||
|
||||
typedef struct {
|
||||
|
@ -1772,6 +1767,10 @@ int sigar_disk_usage_get(sigar_t *sigar, const char *name,
|
|||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
/* XXX this is exactly the same as linux and hpux, solaris is darn close */
|
||||
|
||||
#define SIGAR_FS_BLOCKS_TO_BYTES(val, bsize) ((val * bsize) >> 1)
|
||||
|
||||
int sigar_file_system_usage_get(sigar_t *sigar,
|
||||
const char *dirname,
|
||||
sigar_file_system_usage_t *fsusage)
|
||||
|
@ -1780,14 +1779,19 @@ int sigar_file_system_usage_get(sigar_t *sigar,
|
|||
struct stat sb;
|
||||
int status;
|
||||
struct statfs buf;
|
||||
sigar_uint64_t val, bsize;
|
||||
|
||||
if (statfs((char *)dirname, &buf) != 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_blocks);
|
||||
fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bfree);
|
||||
fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bavail);
|
||||
bsize = buf.f_bsize / 512;
|
||||
val = buf.f_blocks;
|
||||
fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize);
|
||||
val = buf.f_bfree;
|
||||
fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize);
|
||||
val = buf.f_bavail;
|
||||
fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize);
|
||||
fsusage->used = fsusage->total - fsusage->free;
|
||||
fsusage->files = buf.f_files;
|
||||
fsusage->free_files = buf.f_ffree;
|
||||
|
|
Loading…
Reference in New Issue