From: Eric Blake <eblake@redhat.com>
To: Alberto Garcia <berto@igalia.com>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-block@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-devel] [PATCH] throttle: Assert that bkt->max is valid in throttle_compute_wait()
Date: Wed, 13 Sep 2017 08:54:01 -0500 [thread overview]
Message-ID: <a01f3fe2-6315-34d4-6f68-c0e1f38e4e1e@redhat.com> (raw)
In-Reply-To: <20170913082817.24731-1-berto@igalia.com>
[-- Attachment #1: Type: text/plain, Size: 1282 bytes --]
On 09/13/2017 03:28 AM, Alberto Garcia wrote:
> 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 <berto@igalia.com>
> ---
> util/throttle.c | 1 +
> 1 file changed, 1 insertion(+)
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> diff --git a/util/throttle.c b/util/throttle.c
> index 06bf916adc..b38e742da5 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);
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
next prev parent reply other threads:[~2017-09-13 13:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-13 8:28 [Qemu-devel] [PATCH] throttle: Assert that bkt->max is valid in throttle_compute_wait() Alberto Garcia
2017-09-13 13:54 ` Eric Blake [this message]
2017-09-13 16:31 ` Philippe Mathieu-Daudé
2017-09-14 9:00 ` Alberto Garcia
2017-09-18 9:58 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a01f3fe2-6315-34d4-6f68-c0e1f38e4e1e@redhat.com \
--to=eblake@redhat.com \
--cc=berto@igalia.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).