From nobody Mon May 6 11:15:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505291446363476.9382682157433; Wed, 13 Sep 2017 01:30:46 -0700 (PDT) Received: from localhost ([::1]:40880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds34H-0001Hx-B7 for importer@patchew.org; Wed, 13 Sep 2017 04:30:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds32N-0000A2-Kf for qemu-devel@nongnu.org; Wed, 13 Sep 2017 04:28:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ds32J-0000pN-KH for qemu-devel@nongnu.org; Wed, 13 Sep 2017 04:28:47 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:49749) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ds32J-0000nb-8x; Wed, 13 Sep 2017 04:28:43 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ds32G-0005Co-Ao; Wed, 13 Sep 2017 10:28:40 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ds320-0006Rd-Ku; Wed, 13 Sep 2017 11:28:24 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=z17m4eY1u7HBSIGXC8owNUoEz53c4c717bX0f9K9KLI=; b=AVgPlPhROLPhryvEGmNiOBNNDmfAZXCn3ncNSlk7IiE1003HNQpn6K9Q3ydzw4trcAQyKoDAw8qRtx8o7UxOUzpzDmncf/bwcAde5DezV8rpCuXathUYbZUl08V/vnlGYuFmfstgwzbWdXHcWcSY6KBhJomSg3YS1X4HlMbDWEQMJ6colTxwgyeXb4H4mmzcxGmOZdxpZ1Ao6IT1DJkYes93Tkeoc8mVXOyMuV9odLRk6JdFuQ6V2j0DueAVXby3lEfOGU8M/qgTIRAfXxZ8bVMmDYxmcbQkGe3fYzmzFf3uCLMyCCu+O8wQfpJVFSJrtwqkLwi/ieFpNqei3fHJZQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 13 Sep 2017 11:28:17 +0300 Message-Id: <20170913082817.24731-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH] throttle: Assert that bkt->max is valid in throttle_compute_wait() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Alberto Garcia , qemu-block@nongnu.org, Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If bkt->max =3D=3D 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 --- util/throttle.c | 1 + 1 file changed, 1 insertion(+) 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 =3D bkt->burst_level - burst_bucket_size; if (extra > 0) { return throttle_do_compute_wait(bkt->max, extra); --=20 2.11.0