util/main-loop: Fix maximum number of wait objects for win32
PATCH 1/2 util/main-loop: Fix maximum number of wait objects for win32
From: Bin Meng <[email protected]>
The maximum number of wait objects for win32 should be MAXIMUM_WAIT_OBJECTS, not MAXIMUM_WAIT_OBJECTS + 1.
---
util/main-loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
util/main-loop.c +4 -4
@@ -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 };
Signature · 1 line
2.34.1
PATCH 2/2 util/aio-win32: Correct the event array size in aio_poll()
From: Bin Meng <[email protected]>
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.
---
util/aio-win32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
util/aio-win32.c +2 -1
@@ -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 ); events[count++] =event_notifier_get_handle (node->e); } }
Signature · 1 line
2.34.1
Re: [PATCH 2/2] util/aio-win32: Correct the event array size in aio_poll()
Am 05.08.22 um 16:56 schrieb Bin Meng:
Quoted 26 lines
From: Bin Meng <[email protected]>
WaitForMultipleObjects()can only wait forMAXIMUM_WAIT_OBJECTSobject handles. Correct the event array size inaio_poll()and add aassert()to ensure it does not cause out of bound access.Signed-off-by Bin Meng <[email protected]>---
util/aio-win32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)util/aio-win32.c +1
-1@@ -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;
util/aio-win32.c bool aio_poll(AioContext *ctx, bool blocking) · line 372
Quoted 4 lines
util/aio-win32.c +1
-0@@ -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).
Re: [PATCH 2/2] util/aio-win32: Correct the event array size in aio_poll()
Quoted 29 lines · Stefan Weil
Am 05.08.22 um 16:56 schrieb Bin Meng:
Quoted 26 lines
From: Bin Meng <[email protected]>
WaitForMultipleObjects()can only wait forMAXIMUM_WAIT_OBJECTSobject handles. Correct the event array size inaio_poll()and add aassert()to ensure it does not cause out of bound access.Signed-off-by Bin Meng <[email protected]>---
util/aio-win32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)util/aio-win32.c +1
-1@@ -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)
Quoted 8 lines
util/aio-win32.c bool aio_poll(AioContext *ctx, bool blocking) · line 372
Quoted 4 lines
util/aio-win32.c +1
-0QLIST_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_assertfor new code be better? Currently the rest of that file (and most QEMU code) uses assert.
Yeah, I noticed that but didn't do that because I feel it's better to be consistent, at least in this single file.
Changing to g_assert() could be a future patch, if necessary.
Quoted 4 lines
count could also be changed from int to unsigned (which matches better to the unsigned DWORD).
changed in v2.
Quoted 1 line
Reviewed-by Stefan Weil <[email protected]>
Thanks!
Regards,
Bin
Quoted 12 lines · Bin Meng
From: Bin Meng <[email protected]>
The maximum number of wait objects for win32 should be
MAXIMUM_WAIT_OBJECTS, notMAXIMUM_WAIT_OBJECTS+ 1.Signed-off-by Bin Meng <[email protected]>---
util/main-loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Ping?
Philippe Mathieu-Daudé via
Reviewed-by Philippe Mathieu-DaudéQuoted 7 lines · Bin Meng
Quoted 6 lines · Bin Meng
From: Bin Meng <[email protected]>
The maximum number of wait objects for win32 should be
MAXIMUM_WAIT_OBJECTS, notMAXIMUM_WAIT_OBJECTS+ 1.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Bin Meng <[email protected]>---
util/main-loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)Ping?
NB: qemu_del_wait_object() seems dubious in case the same handle is added more than once with qemu_add_wait_object().
Hi
Quoted 7 lines · Bin Meng
From: Bin Meng <[email protected]>
The maximum number of wait objects for win32 should be
MAXIMUM_WAIT_OBJECTS, notMAXIMUM_WAIT_OBJECTS+ 1.Signed-off-by Bin Meng <[email protected]>
Nack,
if wait_objects.num reaches MAXIMUM_WAIT_OBJECTS,
then qemu_del_wait_object() will iterate up to it, and then the branch "if (found)" will access the arrays at position i+1 == MAXIMUM_WAIT_OBJECTS.
Note that the add functions should probably learn to avoid adding the same HANDLE twice, otherwise del is a bit broken.
---
Quoted 29 lines
util/main-loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)util/main-loop.c +4
-4@@ -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};
--
2.34.1
Signature · 1 line
Marc-André Lureau
Quoted 13 lines · Marc-André Lureau
Hi
Quoted 7 lines · Bin Meng
From: Bin Meng <[email protected]>
The maximum number of wait objects for win32 should be
MAXIMUM_WAIT_OBJECTS, notMAXIMUM_WAIT_OBJECTS+ 1.Signed-off-by Bin Meng <[email protected]>
Quoted 8 lines
Nack,
if wait_objects.num reaches
MAXIMUM_WAIT_OBJECTS,then
qemu_del_wait_object()will iterate up to it, and then the branch "if (found)" will access the arrays at position i+1 ==MAXIMUM_WAIT_OBJECTS.Note that the add functions should probably learn to avoid adding the same HANDLE twice, otherwise del is a bit broken.
Thanks for the review. Will fix in v2.
Regards,
Bin