aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2016-01-20 12:21:20 +0800
committerKevin Wolf <kwolf@redhat.com>2016-01-20 13:37:37 +0100
commit972606c4db826f286f7f475551180502859f49b9 (patch)
tree125805ef1ec52a3c930a1c5e900c76410e92b4be /util
parentd62d9dc4b814950dcc8bd261a3e2e9300d9065e6 (diff)
blockdev: Error out on negative throttling option values
extract_common_blockdev_options() uses qemu_opt_get_number() to parse the bps/iops numbers to uint64_t, then converts to double and stores in ThrottleConfig. The actual parsing is done by strtoull() in parse_option_number(). Negative numbers are wrapped to large positive ones, and stored. We used to reject negative numbers since 7d81c1413c9, but this regressed when the option parsing code was changed later. Now fix this again. This time, define an arbitrary large upper limit (1e15), and check the values so both negative and impractically big numbers are caught and reported. Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/throttle.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/util/throttle.c b/util/throttle.c
index 1113671ecf..af4bc95ba3 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -282,22 +282,18 @@ bool throttle_conflicting(ThrottleConfig *cfg)
*/
bool throttle_is_valid(ThrottleConfig *cfg)
{
- bool invalid = false;
int i;
for (i = 0; i < BUCKETS_COUNT; i++) {
- if (cfg->buckets[i].avg < 0) {
- invalid = true;
+ if (cfg->buckets[i].avg < 0 ||
+ cfg->buckets[i].max < 0 ||
+ cfg->buckets[i].avg > THROTTLE_VALUE_MAX ||
+ cfg->buckets[i].max > THROTTLE_VALUE_MAX) {
+ return false;
}
}
- for (i = 0; i < BUCKETS_COUNT; i++) {
- if (cfg->buckets[i].max < 0) {
- invalid = true;
- }
- }
-
- return !invalid;
+ return true;
}
/* check if bps_max/iops_max is used without bps/iops