mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cov: check for overlow math
Add some extre protection to avoid integer overflow type of problems.
This commit is contained in:
parent
5c7d6083a9
commit
3f41b4af55
@ -196,6 +196,7 @@ int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_
|
|||||||
{
|
{
|
||||||
struct dm_vdo_status_parse_result result;
|
struct dm_vdo_status_parse_result result;
|
||||||
char *dm_name;
|
char *dm_name;
|
||||||
|
uint64_t blocks;
|
||||||
|
|
||||||
status->usage = DM_PERCENT_INVALID;
|
status->usage = DM_PERCENT_INVALID;
|
||||||
status->saving = DM_PERCENT_INVALID;
|
status->saving = DM_PERCENT_INVALID;
|
||||||
@ -227,7 +228,9 @@ int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_
|
|||||||
result.status->total_blocks);
|
result.status->total_blocks);
|
||||||
status->saving = dm_make_percent(status->logical_blocks_used - status->data_blocks_used,
|
status->saving = dm_make_percent(status->logical_blocks_used - status->data_blocks_used,
|
||||||
status->logical_blocks_used);
|
status->logical_blocks_used);
|
||||||
status->data_usage = dm_make_percent(status->data_blocks_used * DM_VDO_BLOCK_SIZE,
|
/* coverity needs to use a local variable to handle check here */
|
||||||
|
status->data_usage = dm_make_percent(((blocks = status->data_blocks_used) < (ULLONG_MAX / DM_VDO_BLOCK_SIZE)) ?
|
||||||
|
(blocks * DM_VDO_BLOCK_SIZE) : ULLONG_MAX,
|
||||||
first_seg(vdo_pool_lv)->vdo_pool_virtual_extents *
|
first_seg(vdo_pool_lv)->vdo_pool_virtual_extents *
|
||||||
(uint64_t) vdo_pool_lv->vg->extent_size);
|
(uint64_t) vdo_pool_lv->vg->extent_size);
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,7 @@ static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, size_t *mstats
|
|||||||
for (len = 0 ; len < _maps_len; len += n) {
|
for (len = 0 ; len < _maps_len; len += n) {
|
||||||
if (!(n = read(_maps_fd, _maps_buffer + len, _maps_len - len)))
|
if (!(n = read(_maps_fd, _maps_buffer + len, _maps_len - len)))
|
||||||
break; /* EOF */
|
break; /* EOF */
|
||||||
if (n == -1) {
|
if ((n < 0) || (len >= (SSIZE_MAX - n))) {
|
||||||
log_sys_debug("read", _procselfmaps);
|
log_sys_debug("read", _procselfmaps);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1444,7 +1444,8 @@ static void _stats_walk_next_present(const struct dm_stats *dms,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* advance to next present, non-skipped region or end */
|
/* advance to next present, non-skipped region or end */
|
||||||
while (++(*cur_r) <= dms->max_region) {
|
while ((*cur_r < UINT64_MAX) &&
|
||||||
|
++(*cur_r) <= dms->max_region) {
|
||||||
cur = &dms->regions[*cur_r];
|
cur = &dms->regions[*cur_r];
|
||||||
if (!_stats_region_present(cur))
|
if (!_stats_region_present(cur))
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user