From patchwork Wed Feb 20 01:02:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1044992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44409M0dsjz9s00 for ; Wed, 20 Feb 2019 12:18:31 +1100 (AEDT) Received: from localhost ([127.0.0.1]:57484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwGWq-00025C-Sj for incoming@patchwork.ozlabs.org; Tue, 19 Feb 2019 20:18:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwGQC-0005cx-Mw for qemu-devel@nongnu.org; Tue, 19 Feb 2019 20:11:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwGPy-0004ov-7E for qemu-devel@nongnu.org; Tue, 19 Feb 2019 20:11:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42303) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwGPj-0003tM-Ma; Tue, 19 Feb 2019 20:11:10 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3402985541; Wed, 20 Feb 2019 01:08:34 +0000 (UTC) Received: from x1w.redhat.com (unknown [10.40.205.222]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AAD91001E7E; Wed, 20 Feb 2019 01:08:23 +0000 (UTC) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Prasad J Pandit , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Date: Wed, 20 Feb 2019 02:02:30 +0100 Message-Id: <20190220010232.18731-24-philmd@redhat.com> In-Reply-To: <20190220010232.18731-1-philmd@redhat.com> References: <20190220010232.18731-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 20 Feb 2019 01:08:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 23/25] hw/ipmi: Assert outlen > outpos 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: Corey Minyard , Stefano Stabellini , Samuel Thibault , Li Zhijian , Amit Shah , "Michael S. Tsirkin" , Jason Wang , Cornelia Huck , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Paul Durrant , qemu-ppc@nongnu.org, Gerd Hoffmann , Pavel Dovgalyuk , Zhang Chen , Anthony Perard , xen-devel@lists.xenproject.org, Stefan Berger , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" A througfull audit show that all time data is added to outbuf[], 'outlen' is incremented. Then at creation and each time continue_send() returns it pass thru check_reset which resets 'outpos', thus we always have 'outlen >= outpos'. Also due to the check on entry, we know outlen != 0. We can then add an assertion on 'outlen > outpos', which will helps the next patch to safely convert 'outlen - outpos' as an unsigned type (size_t). Make this assertion explicit by casting 'outlen - outpos' size_t. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Corey Minyard --- hw/ipmi/ipmi_bmc_extern.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c index bf0b7ee0f5..ca61b04942 100644 --- a/hw/ipmi/ipmi_bmc_extern.c +++ b/hw/ipmi/ipmi_bmc_extern.c @@ -107,8 +107,9 @@ static void continue_send(IPMIBmcExtern *ibe) goto check_reset; } send: + assert(ibe->outlen > ibe->outpos); ret = qemu_chr_fe_write(&ibe->chr, ibe->outbuf + ibe->outpos, - ibe->outlen - ibe->outpos); + (size_t)(ibe->outlen - ibe->outpos)); if (ret > 0) { ibe->outpos += ret; }