From: Alberto Garcia Date: Wed, 13 Sep 2017 08:28:17 +0000 (+0300) Subject: throttle: Assert that bkt->max is valid in throttle_compute_wait() X-Git-Tag: v2.11.0-rc0~76^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b5806108d20fc32b4692e721d8bd6376f4ca4a69;p=thirdparty%2Fqemu.git throttle: Assert that bkt->max is valid in throttle_compute_wait() If bkt->max == 0 and bkt->burst_length > 1 then we could have a division by 0 in throttle_do_compute_wait(). That configuration is however not permitted and is already detected by throttle_is_valid(), but let's assert it in throttle_compute_wait() to make it explicit. Found by Coverity (CID: 1381016). Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- diff --git a/util/throttle.c b/util/throttle.c index 06bf916adc9..b38e742da53 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -124,6 +124,7 @@ int64_t throttle_compute_wait(LeakyBucket *bkt) /* If the main bucket is not full yet we still have to check the * burst bucket in order to enforce the burst limit */ if (bkt->burst_length > 1) { + assert(bkt->max > 0); /* see throttle_is_valid() */ extra = bkt->burst_level - burst_bucket_size; if (extra > 0) { return throttle_do_compute_wait(bkt->max, extra);