From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v3 23/25] hw/ipmi: Assert outlen > outpos List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Prasad J Pandit , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Cc: Jason Wang , Anthony Perard , qemu-ppc@nongnu.org, Stefan Berger , David Gibson , Gerd Hoffmann , Zhang Chen , xen-devel@lists.xenproject.org, Cornelia Huck , Samuel Thibault , Christian Borntraeger , Amit Shah , Li Zhijian , Corey Minyard , "Michael S. Tsirkin" , Paul Durrant , Halil Pasic , Stefano Stabellini , qemu-s390x@nongnu.org, Pavel Dovgalyuk , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 >=3D outpos'. Also due to the check on entry, we know outlen !=3D 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=C3=A9 --- 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 =3D 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 +=3D ret; } --=20 2.20.1