[SIGAR-85] Fix possible integer overflow in sigar_file_system_usage
This commit is contained in:
parent
2e63fd91b8
commit
68ae3137c1
|
@ -416,9 +416,6 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
|
||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \
|
|
||||||
(((sigar_uint64_t)buf.f * (buf.f_bsize / 512)) >> 1)
|
|
||||||
|
|
||||||
#define SWI_MAXMIB 3
|
#define SWI_MAXMIB 3
|
||||||
|
|
||||||
#ifdef SIGAR_FREEBSD5
|
#ifdef SIGAR_FREEBSD5
|
||||||
|
@ -1721,19 +1718,26 @@ int sigar_disk_usage_get(sigar_t *sigar, const char *name,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SIGAR_FS_BLOCKS_TO_BYTES(val, bsize) ((val * bsize) >> 1)
|
||||||
|
|
||||||
int sigar_file_system_usage_get(sigar_t *sigar,
|
int sigar_file_system_usage_get(sigar_t *sigar,
|
||||||
const char *dirname,
|
const char *dirname,
|
||||||
sigar_file_system_usage_t *fsusage)
|
sigar_file_system_usage_t *fsusage)
|
||||||
{
|
{
|
||||||
struct statfs buf;
|
struct statfs buf;
|
||||||
|
sigar_uint64_t val, bsize;
|
||||||
|
|
||||||
if (statfs(dirname, &buf) < 0) {
|
if (statfs(dirname, &buf) < 0) {
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_blocks);
|
bsize = buf.f_bsize / 512;
|
||||||
fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bfree);
|
val = buf.f_blocks;
|
||||||
fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bavail);
|
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->used = fsusage->total - fsusage->free;
|
||||||
fsusage->files = buf.f_files;
|
fsusage->files = buf.f_files;
|
||||||
fsusage->free_files = buf.f_ffree;
|
fsusage->free_files = buf.f_ffree;
|
||||||
|
|
Loading…
Reference in New Issue