From patchwork Wed Oct 19 10:20:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 13011556 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 E03BFC4332F for ; Wed, 19 Oct 2022 10:24:54 +0000 (UTC) Received: from localhost ([::1]:44724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ol6Fo-0001Kq-RF for qemu-devel@archiver.kernel.org; Wed, 19 Oct 2022 06:24:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ol6BW-0004w2-2f for qemu-devel@nongnu.org; Wed, 19 Oct 2022 06:20:27 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:37528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ol6BT-0001d3-T9 for qemu-devel@nongnu.org; Wed, 19 Oct 2022 06:20:25 -0400 Received: by mail-pf1-x434.google.com with SMTP id 3so16797253pfw.4 for ; Wed, 19 Oct 2022 03:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Wzwj+fpAeUi9phgWTgcb8wbChvupV5gkpnSWwIw/I28=; b=XtUoxu9QK2RrE/HwfeWClBQKSo9vkv+/BUp0xWOqqo1AGKp9eFULiaTx0ZLmkzHH5W JxXYIDQ00lsSWUZOqrWGtcYIkRs/z1050ozJhrlhPjJuzp1+xU6i0liWEzSNY9GnVbDq I5vu9DLr47i18k18+z4jGC4G8qoVExrdSc1P/qfliumleMOkyLsjWQnyAyClBjLxLkMW fi69bsRwSkmmoVeYx6YmswHtWMh05RN4TPPhj5No3mHrC3X+MSPxtInJLq8yEueB/xVx OmONn6cncdCHXm7D1VEIT5qZ0JiL+TtrZ5o8sf2cTATh9sPIfV6kK83mloLVKZ6UdAjE fixQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Wzwj+fpAeUi9phgWTgcb8wbChvupV5gkpnSWwIw/I28=; b=JpLrycIZlF4ceMIOaANtE9PmUC+/4qG/p+jPXXmGQ4CE6YFEcyq3Du4WMHWZrnOeui Hf3DACXRICaAsAHXyu21U8+xe05z01qmrbHda2Z/cDsBovNRgaRkYc/x9kwktFygM5f6 obeCOMAlaxixGyVHdq/+QZ/CvsZymUUjiOZgJDUIQ8OgvN6l2fiED7rSgspP7BOHZE4p MXXmaurJNSuRc8xXrykEZznJ6n1yxmMO6XG0rye1KJmJTYK2ftjkQOx2xhdACIFPRvNt iaV/Lg0p1B/kuLIQf8RlpdEDEOkfIi2TbdWyIi1x2cYJ7+wMkmBDAYcisgYbFwv+B0mI 9V6Q== X-Gm-Message-State: ACrzQf2VoRR43MNIAL88/ubsdklY/Nn30me3464AF9vym1gAyqHhkzi5 YQvHfOafxy2DoKTjgoMH4+q2zD/mzE0hhg== X-Google-Smtp-Source: AMsMyM7QjR1XRUIq/bpjPlEHUdHCBLg8bpKZ+M0pvv75EUfF2L2dbTo7G2WU5eWXqkNNJbgwQvQpgA== X-Received: by 2002:a63:91c7:0:b0:460:924:a34e with SMTP id l190-20020a6391c7000000b004600924a34emr6495368pge.492.1666174822161; Wed, 19 Oct 2022 03:20:22 -0700 (PDT) Received: from ubuntu.. ([65.20.73.185]) by smtp.gmail.com with ESMTPSA id u18-20020a170902e5d200b0017f9db0236asm10543879plf.82.2022.10.19.03.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 03:20:21 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= Cc: Bin Meng , Paolo Bonzini Subject: [PATCH v4 1/3] util/main-loop: Fix maximum number of wait objects for win32 Date: Wed, 19 Oct 2022 18:20:13 +0800 Message-Id: <20221019102015.2441622-1-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" From: Bin Meng The maximum number of wait objects for win32 should be MAXIMUM_WAIT_OBJECTS, not MAXIMUM_WAIT_OBJECTS + 1. Signed-off-by: Bin Meng Reviewed-by: Philippe Mathieu-Daudé --- Changes in v4: - make the out of bounds access protection explicit Changes in v3: - move the check of adding the same HANDLE twice to a separete patch Changes in v2: - fix the logic in qemu_add_wait_object() to avoid adding the same HANDLE twice util/main-loop.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/main-loop.c b/util/main-loop.c index f00a25451b..de38876064 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -363,10 +363,10 @@ void qemu_del_polling_cb(PollingFunc *func, void *opaque) /* Wait objects support */ typedef struct WaitObjects { int num; - int revents[MAXIMUM_WAIT_OBJECTS + 1]; - HANDLE events[MAXIMUM_WAIT_OBJECTS + 1]; - WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1]; - void *opaque[MAXIMUM_WAIT_OBJECTS + 1]; + int revents[MAXIMUM_WAIT_OBJECTS]; + HANDLE events[MAXIMUM_WAIT_OBJECTS]; + WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS]; + void *opaque[MAXIMUM_WAIT_OBJECTS]; } WaitObjects; static WaitObjects wait_objects = {0}; @@ -395,7 +395,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) if (w->events[i] == handle) { found = 1; } - if (found) { + if (found && i < (MAXIMUM_WAIT_OBJECTS - 1)) { w->events[i] = w->events[i + 1]; w->func[i] = w->func[i + 1]; w->opaque[i] = w->opaque[i + 1]; From patchwork Wed Oct 19 10:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 13011557 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 35373C4332F for ; Wed, 19 Oct 2022 10:24:57 +0000 (UTC) Received: from localhost ([::1]:44708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ol6Fr-0001Dn-BJ for qemu-devel@archiver.kernel.org; Wed, 19 Oct 2022 06:24:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ol6Bm-0005Lm-Vn for qemu-devel@nongnu.org; Wed, 19 Oct 2022 06:20:44 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:41652) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ol6BX-0001eN-SS for qemu-devel@nongnu.org; Wed, 19 Oct 2022 06:20:42 -0400 Received: by mail-pl1-x62e.google.com with SMTP id l4so16666152plb.8 for ; Wed, 19 Oct 2022 03:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u2RsuK/FA5n9JyAC7qgdJyab94SYLZOr92ElbU7zW+U=; b=LwDCFLy6Zp+D8M30YhevcJxmww7Gh9Szt7s7rkk+6SasVLs86ZfVq6hw2y91xQEy+x giWaqzqb0LymgaTHg8uxkrB5WkhliuldgM3WOGNMZIDBIaMy9P7TrvpP/pQbhxf2FiZ0 C+fhxj5wzoxDnUGKII99kmDdNXWQPJQ4W8HAF1+AwfHw/zWcM3SAAYJdPKpdIf+gObQ3 LUmkeNLTr9/NY2FjmyReWVPtS9nJLi/3OMSojzIc4v/gVoon6ogc1H5DoHS/jA0x6tsM t/n4/fHFPFzna7Wq992NhjtYf7U5F/8IWe8VQjtnLX25VrYAeFp3MSNqal3MZWXNe3Mn 49YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u2RsuK/FA5n9JyAC7qgdJyab94SYLZOr92ElbU7zW+U=; b=3SvLOi63uA7ajPRqzn9Gfm/uwmtxA75QI79ncEIwiBbRfJcFkK0QqNAh1AQMl/bJlM 8T3dUFqFQRqAWbSDceXdfSVuKfpvQ6Mkeuec0kZcT9Qlg1Vr2HQKRTGF7TooGA2m58gD t0PS0o+O+iUnFchoavhEBRiqOfSnXpi/2RWBRXWAHLsgDev/vfqdO1K/FVPgxRIzxm2G hMJT7MQsVCCf5CNLOLwZFCOqfBAf5xiBUQg9e8gCPKFnA4SfuxgXVbqeJTJOnIwgVbZA +nNqfqj1QRxcMWTr6/7wTWgUoDN7uOOzxMwMvZGMVytWpEs9zNeVFsaNdb6mR0jcNjMk pSww== X-Gm-Message-State: ACrzQf0Y2AVG/rCq1R4/dUBLTvwfjM+Oie0gOm7RiNbXIRJTWqCXkxwM Q96rQfeEavkGDw8g2M8Pos2YUASDQJpbaQ== X-Google-Smtp-Source: AMsMyM6caV6Py2BtOxeV3zj0BFBF+C3AhdRTmh9WDYmjunQtTiQ87zCJnekUMEmS51ZwwKuvN/jbww== X-Received: by 2002:a17:902:e945:b0:179:ce23:dd4d with SMTP id b5-20020a170902e94500b00179ce23dd4dmr7552933pll.68.1666174826161; Wed, 19 Oct 2022 03:20:26 -0700 (PDT) Received: from ubuntu.. ([65.20.73.185]) by smtp.gmail.com with ESMTPSA id u18-20020a170902e5d200b0017f9db0236asm10543879plf.82.2022.10.19.03.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 03:20:25 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= Cc: Bin Meng , Paolo Bonzini Subject: [PATCH v4 2/3] util/main-loop: Avoid adding the same HANDLE twice Date: Wed, 19 Oct 2022 18:20:14 +0800 Message-Id: <20221019102015.2441622-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019102015.2441622-1-bmeng.cn@gmail.com> References: <20221019102015.2441622-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" From: Bin Meng Fix the logic in qemu_add_wait_object() to avoid adding the same HANDLE twice, as the behavior is undefined when passing an array that contains same HANDLEs to WaitForMultipleObjects() API. Signed-off-by: Bin Meng Reviewed-by: Philippe Mathieu-Daudé --- (no changes since v3) Changes in v3: - new patch: avoid adding the same HANDLE twice include/qemu/main-loop.h | 2 ++ util/main-loop.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index aac707d073..3c9a9a982d 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -157,6 +157,8 @@ typedef void WaitObjectFunc(void *opaque); * in the main loop's calls to WaitForMultipleObjects. When the handle * is in a signaled state, QEMU will call @func. * + * If the same HANDLE is added twice, this function returns -1. + * * @handle: The Windows handle to be observed. * @func: A function to be called when @handle is in a signaled state. * @opaque: A pointer-size value that is passed to @func. diff --git a/util/main-loop.c b/util/main-loop.c index de38876064..10fa74c6e3 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -373,10 +373,20 @@ static WaitObjects wait_objects = {0}; int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) { + int i; WaitObjects *w = &wait_objects; + if (w->num >= MAXIMUM_WAIT_OBJECTS) { return -1; } + + for (i = 0; i < w->num; i++) { + /* check if the same handle is added twice */ + if (w->events[i] == handle) { + return -1; + } + } + w->events[w->num] = handle; w->func[w->num] = func; w->opaque[w->num] = opaque; From patchwork Wed Oct 19 10:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 13011555 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 42B49C433FE for ; Wed, 19 Oct 2022 10:24:54 +0000 (UTC) Received: from localhost ([::1]:44702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ol6Fo-0001Dg-C1 for qemu-devel@archiver.kernel.org; Wed, 19 Oct 2022 06:24:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ol6Bh-0005EV-L3; Wed, 19 Oct 2022 06:20:37 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:45850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ol6Bd-0001jk-O3; Wed, 19 Oct 2022 06:20:37 -0400 Received: by mail-pf1-x436.google.com with SMTP id 67so16770376pfz.12; Wed, 19 Oct 2022 03:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tSFcI5M+TIgAqd7Z7uglAUolB/9gROW5YVIR0p9viyw=; b=NwSKciWocVnLOyVxWlmRi1Wwl02SVapb9K8UGk34K+KOrJ9VSNuLFImS+r2TJqdMV6 OodisCB9NfOAY1Kg9BRXgu/6ulOV1cI9OFJUn3BpEwH4qfKoHNwhKFSSofexvF5/V1Fv SX08eauXKzryXaSDNxc8nCBZ3i+SbfLMEmdKeWlXqyezBT501D8JZUkjfZXne/+dN6uO N6or860I29l3df/TRckDElSAS12uBxi/Ok1aOJIaKUioF5YuhV019422yEOn4B7iN5qq rNT0vsRz9aiAs5zPBATJoKKuUxBF1s2dQVBfP/17EAfUTAoWuRM5LMCe4eIDVmkD6p3k SBOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tSFcI5M+TIgAqd7Z7uglAUolB/9gROW5YVIR0p9viyw=; b=vutcbZ+yBDeaekokXBk9xP3/DOhgiI/MG8m98L4aH8PwIhU8C3gn6xRWJxRLlm/CFn Ne0zjizLC2SXzyTCXFRTcNZQMZkvACZexBNpvgmK9QMEjdUoLb1Jl3lW1lTuGw5adjcA JVHaCuBxre85HsTi+bdO1Ukn9S7Jg3+L2bBWK85KmeAvFVAn/17prNbLAziPw9ugWL0f ARVES2b6KCjpylmrQNod3dyvV9lJWNuxDMlWuPMgi5NOg3lotuc4vmRMwvXZHxqEBo9s 2f+6keba6azkDbq8J7bCtPtxEzpSGW1HYIbRdH3t/Q0Z3PF8XrTaAWIl1WmjKt7c0KYt hNPA== X-Gm-Message-State: ACrzQf2WXHcez7nWN1RjuutY65W2229fOdtojXO6qw0yUq91jYC0OrHO dcZNN9toN3FHij+2mKD4vOGcFGB4KVh/aw== X-Google-Smtp-Source: AMsMyM6L6meIzxEXpf42LdYGSfaxLZ+Oqvwi/89VGX42oqnV50GJbS8aDphjaOMIqkCV1VCdRXVnFA== X-Received: by 2002:a63:5946:0:b0:461:e1b9:c5a5 with SMTP id j6-20020a635946000000b00461e1b9c5a5mr6673171pgm.56.1666174831235; Wed, 19 Oct 2022 03:20:31 -0700 (PDT) Received: from ubuntu.. ([65.20.73.185]) by smtp.gmail.com with ESMTPSA id u18-20020a170902e5d200b0017f9db0236asm10543879plf.82.2022.10.19.03.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 03:20:30 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= Cc: Bin Meng , Stefan Weil , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org Subject: [PATCH v4 3/3] util/aio-win32: Correct the event array size in aio_poll() Date: Wed, 19 Oct 2022 18:20:15 +0800 Message-Id: <20221019102015.2441622-3-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019102015.2441622-1-bmeng.cn@gmail.com> References: <20221019102015.2441622-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" 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 Reviewed-by: Stefan Weil Reviewed-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé --- (no changes since v2) Changes in v2: - change 'count' to unsigned util/aio-win32.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/aio-win32.c b/util/aio-win32.c index 44003d645e..80cfe012ad 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -326,9 +326,9 @@ 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; + unsigned 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); events[count++] = event_notifier_get_handle(node->e); } }