Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7636C00140 for ; Fri, 5 Aug 2022 15:10:21 +0000 (UTC) Received: from localhost ([::1]:36972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJyxw-00080Z-W5 for qemu-devel@archiver.kernel.org; Fri, 05 Aug 2022 11:10:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJyx9-00079s-0e; Fri, 05 Aug 2022 11:09:31 -0400 Received: from mail.weilnetz.de ([37.120.169.71]:56382 helo=mail.v2201612906741603.powersrv.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJyx6-0005YR-Uf; Fri, 05 Aug 2022 11:09:30 -0400 Received: from [192.168.178.59] (p57b42628.dip0.t-ipconnect.de [87.180.38.40]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.v2201612906741603.powersrv.de (Postfix) with ESMTPSA id 40400DA0EBF; Fri, 5 Aug 2022 17:09:25 +0200 (CEST) Message-ID: Date: Fri, 5 Aug 2022 17:09:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: Bin Meng , qemu-devel@nongnu.org Cc: Bin Meng , Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org References: <20220805145617.952881-1-bmeng.cn@gmail.com> <20220805145617.952881-2-bmeng.cn@gmail.com> Subject: Re: [PATCH 2/2] util/aio-win32: Correct the event array size in aio_poll() In-Reply-To: <20220805145617.952881-2-bmeng.cn@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=37.120.169.71; envelope-from=sw@weilnetz.de; helo=mail.v2201612906741603.powersrv.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Stefan Weil From: Stefan Weil via Am 05.08.22 um 16:56 schrieb Bin Meng: > From: Bin Meng > > WaitForMultipleObjects() can only wait for MAXIMUM_WAIT_OBJECTS > object handles. Correct the event array size in aio_poll() and > add a assert() to ensure it does not cause out of bound access. > > Signed-off-by: Bin Meng > --- > > util/aio-win32.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/util/aio-win32.c b/util/aio-win32.c > index 44003d645e..8cf5779567 100644 > --- a/util/aio-win32.c > +++ b/util/aio-win32.c > @@ -326,7 +326,7 @@ void aio_dispatch(AioContext *ctx) > bool aio_poll(AioContext *ctx, bool blocking) > { > AioHandler *node; > - HANDLE events[MAXIMUM_WAIT_OBJECTS + 1]; > + HANDLE events[MAXIMUM_WAIT_OBJECTS]; > bool progress, have_select_revents, first; > int count; > int timeout; > @@ -369,6 +369,7 @@ bool aio_poll(AioContext *ctx, bool blocking) > QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) { > if (!node->deleted && node->io_notify > && aio_node_check(ctx, node->is_external)) { > + assert(count < MAXIMUM_WAIT_OBJECTS); Would using g_assert for new code be better? Currently the rest of that file (and most QEMU code) uses assert. count could also be changed from int to unsigned (which matches better to the unsigned DWORD). Reviewed-by: Stefan Weil