Received: from eggs.gnu.org ([2001:4830:134:3::10]:49429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTVmS-0006HF-Kl for qemu-devel@nongnu.org; Mon, 15 Sep 2014 08:53:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTVmE-0006sk-Tc for qemu-devel@nongnu.org; Mon, 15 Sep 2014 08:53:20 -0400 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:48709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTVmE-0006sX-N8 for qemu-devel@nongnu.org; Mon, 15 Sep 2014 08:53:06 -0400 Received: by mail-wi0-f177.google.com with SMTP id em10so4110014wid.16 for ; Mon, 15 Sep 2014 05:53:05 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 15 Sep 2014 14:52:58 +0200 Message-Id: <1410785578-29277-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] aio-win32: avoid out-of-bounds access to the events array List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, geleman@gmail.com, famz@redhat.com, stefanha@redhat.com If ret is WAIT_TIMEOUT and there was an event returned by select(), we can write to a location after the end of the array. But in that case we can retry the WaitForMultipleObjects call with the same set of events, so just move the event[ret - WAIT_OBJECT_0] assignment inside the existin conditional. Reported-by: TeLeMan Signed-off-by: Paolo Bonzini --- aio-win32.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/aio-win32.c b/aio-win32.c index 61e3d2d..89f9e1f 100644 --- a/aio-win32.c +++ b/aio-win32.c @@ -335,6 +335,7 @@ bool aio_poll(AioContext *ctx, bool blocking) event = NULL; if ((DWORD) (ret - WAIT_OBJECT_0) < count) { event = events[ret - WAIT_OBJECT_0]; + events[ret - WAIT_OBJECT_0] = events[--count]; } else if (!have_select_revents) { break; } @@ -343,9 +344,6 @@ bool aio_poll(AioContext *ctx, bool blocking) blocking = false; progress |= aio_dispatch_handlers(ctx, event); - - /* Try again, but only call each handler once. */ - events[ret - WAIT_OBJECT_0] = events[--count]; } progress |= timerlistgroup_run_timers(&ctx->tlg); -- 2.1.0