util/main-loop: Fix maximum number of wait objects for win32
PATCH v3 1/3 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.
---
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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
util/main-loop.c +7 -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 };
@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }if (found) { w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ];
Signature · 1 line
2.34.1
PATCH v3 2/3 util/main-loop: Avoid adding the same HANDLE twice
From: Bin Meng <[email protected]>
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.
---
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(+)
include/qemu/main-loop.h +2 -0
@@ -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.
util/main-loop.c +10 -0
@@ -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;
Signature · 1 line
2.34.1
Re: [PATCH v3 2/3] util/main-loop: Avoid adding the same HANDLE twice
Quoted 7 lines · Bin Meng
From: Bin Meng <[email protected]>
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 toWaitForMultipleObjects()API.Signed-off-by Bin Meng <[email protected]>
Quoted 8 lines
---
Changes in v3:
- new patch: avoid adding the same HANDLE twiceinclude/qemu/main-loop.h | 2 ++ util/main-loop.c | 10 ++++++++++ 2 files changed, 12 insertions(+)
Re: [PATCH v3 2/3] util/main-loop: Avoid adding the same HANDLE twice
In reply to Bin MengQuoted 5 lines · Bin Meng
From: Bin Meng <[email protected]>
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 toWaitForMultipleObjects()API.
Have you encountered this problem in the real world, or is this just a flaw you spotted through code inspection ?
Essentially I'm wondering if there's any known caller that is making this mistake of adding it twice ?
Quoted 53 lines
Signed-off-by Bin Meng <[email protected]>---
Changes in v3:
- new patch: avoid adding the same HANDLE twiceinclude/qemu/main-loop.h | 2 ++ util/main-loop.c | 10 ++++++++++ 2 files changed, 12 insertions(+)include/qemu/main-loop.h +2
-0@@ -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. util/main-loop.c +10
-0@@ -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;Signature · 1 line
2.34.1
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v3 2/3] util/main-loop: Avoid adding the same HANDLE twice
Hi Daniel,
Quoted 10 lines · Daniel P. Berrangé
Quoted 5 lines · Bin Meng
From: Bin Meng <[email protected]>
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 toWaitForMultipleObjects()API.Have you encountered this problem in the real world, or is this just a flaw you spotted through code inspection ?
No. This was noticed as part of debugging [1] and code inspection was done for all possible suspicious places.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 3 lines
Essentially I'm wondering if there's any known caller that is making this mistake of adding it twice ?
No known caller at this call chain. But there is another in the QIO socket channel APIs that may add the same handle twice, fortunately that scenario is handled properly in the GLib internally.
Quoted 5 lines
Quoted 5 lines
Signed-off-by Bin Meng <[email protected]>---
Quoted 7 lines
Quoted 7 lines
Changes in v3:
- new patch: avoid adding the same HANDLE twiceinclude/qemu/main-loop.h | 2 ++ util/main-loop.c | 10 ++++++++++ 2 files changed, 12 insertions(+)
Regards,
Bin
PATCH v3 3/3 util/aio-win32: Correct the event array size in aio_poll()
In reply to Bin MengFrom: 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.
---
(no changes since v2)
Changes in v2:
- change 'count' to unsigned
util/aio-win32.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
util/aio-win32.c +3 -2
@@ -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); } }
Signature · 1 line
2.34.1
Re: [PATCH v3 3/3] util/aio-win32: Correct the event array size in aio_poll()
Quoted 11 lines · Bin Meng
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]>Reviewed-by Stefan Weil <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
Quoted 7 lines
(no changes since v2)
Changes in v2:
- change 'count' to unsignedutil/aio-win32.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Re: [PATCH v3 3/3] util/aio-win32: Correct the event array size in aio_poll()
In reply to Bin MengQuoted 24 lines · Bin Meng
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]>Reviewed-by Stefan Weil <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
(no changes since v2)
Changes in v2:
- change 'count' to unsignedutil/aio-win32.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)util/aio-win32.c +0
-0
util/aio-win32.c void aio_dispatch(AioContext *ctx) · line 329
Quoted 5 lines
util/aio-win32.c +1
-1@@ -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 ];
Interestingly, the orignial + 1 was entirely pointless, since the aio_poll impl has no bounds checking at all, until your new assert.
Quoted 7 lines
util/aio-win32.c +1
-1bool progress, have_select_revents, first; -int count; +unsigned count;int timeout;/*
util/aio-win32.c bool aio_poll(AioContext *ctx, bool blocking) · line 375
Quoted 7 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 ); events[count++] =event_notifier_get_handle (node->e); } }
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 39 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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 };
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
Quoted 10 lines
util/main-loop.c +3
-1@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }if (found) { w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ]; --
Ping for this series?
Quoted 39 lines · Bin Meng
Quoted 37 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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 ;
Quoted 14 lines
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
Quoted 12 lines
util/main-loop.c +3
-1static WaitObjects wait_objects = {0 };@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }if (found) { w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ]; --Ping for this series?
Ping?
Hi
Quoted 39 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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};
util/main-loop.c void qemu_del_wait_object(HANDLE handle, · line 402
Quoted 8 lines
util/main-loop.c +3
-0@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }
hmm
Quoted 4 lines
util/main-loop.c +0
-0if (found) {w->events[i] = w->events[i + 1]; w->func[i] = w->func[i + 1];
The way deletion works is by moving the i+1 element (which is always zeroed for i == MAXIMUM_WAIT_OBJECTS) to i.
After your patch, for i == MAXIMUM_WAIT_OBJECTS, we no longer clear the last value, and instead rely simply on updated w->num:
if (found) {
w->num--;
}So your patch looks ok to me, but I prefer the current code.
Paolo, what do you say?
Hi Paolo,
Quoted 63 lines · Marc-André Lureau
Hi
Quoted 39 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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 };util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 400
Quoted 6 lines
util/main-loop.c +3
-0@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }hmm
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 403
Quoted 4 lines
util/main-loop.c +0
-0if (found) { w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ];The way deletion works is by moving the i+1 element (which is always zeroed for i ==
MAXIMUM_WAIT_OBJECTS) to i.After your patch, for i ==
MAXIMUM_WAIT_OBJECTS, we no longer clear the last value, and instead rely simply on updatedw->num:
Quoted 7 lines
if (found) { w->num--; }So your patch looks ok to me, but I prefer the current code.
Paolo, what do you say?
Ping?
Regards,
Bin
Hi Paolo,
Quoted 72 lines · Bin Meng
Hi Paolo,
Quoted 67 lines · Marc-André Lureau
Hi
Quoted 39 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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 };util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 400
Quoted 6 lines
util/main-loop.c +3
-0@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }hmm
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 403
Quoted 4 lines
util/main-loop.c +0
-0if (found) { w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ];The way deletion works is by moving the i+1 element (which is always zeroed for i ==
MAXIMUM_WAIT_OBJECTS) to i.After your patch, for i ==
MAXIMUM_WAIT_OBJECTS, we no longer clear the last value, and instead rely simply on updatedw->num:if (found) { w->num--; }
Quoted 6 lines
Quoted 3 lines
So your patch looks ok to me, but I prefer the current code.
Paolo, what do you say?
Ping?
Ping?
Regards,
Bin
+more people
Quoted 76 lines · Bin Meng
Hi Paolo,
Quoted 72 lines · Bin Meng
Hi Paolo,
Quoted 67 lines · Marc-André Lureau
Hi
Quoted 39 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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 };util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 400
Quoted 6 lines
util/main-loop.c +3
-0@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }hmm
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 403
Quoted 4 lines
util/main-loop.c +0
-0if (found) { w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ];The way deletion works is by moving the i+1 element (which is always zeroed for i ==
MAXIMUM_WAIT_OBJECTS) to i.After your patch, for i ==
MAXIMUM_WAIT_OBJECTS, we no longer clear the last value, and instead rely simply on updatedw->num:if (found) { w->num--; }
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
So your patch looks ok to me, but I prefer the current code.
Paolo, what do you say?
Ping?
Ping?
Could this series be merged? Thanks,
Regards,
Bin
+Daniel,
Quoted 84 lines · Bin Meng
+more people
Quoted 80 lines · Bin Meng
Hi Paolo,
Quoted 76 lines · Bin Meng
Hi Paolo,
Quoted 70 lines · Marc-André Lureau
Hi
Quoted 39 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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 };util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 400
Quoted 6 lines
util/main-loop.c +3
-0@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }hmm
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 403
Quoted 4 lines
util/main-loop.c +0
-0if (found) { w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ];The way deletion works is by moving the i+1 element (which is always zeroed for i ==
MAXIMUM_WAIT_OBJECTS) to i.After your patch, for i ==
MAXIMUM_WAIT_OBJECTS, we no longer clear the last value, and instead rely simply on updatedw->num:if (found) { w->num--; }So your patch looks ok to me, but I prefer the current code.
Paolo, what do you say?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Ping?
Ping?
Could this series be merged? Thanks,
Since Polo keeps silent, Daniel would you help queue this series? Thanks!
Regards,
Bin
Quoted 38 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]>---
Changes in v3:
- move the check of adding the same HANDLE twice to a separete patchChanges in v2:
- fix the logic inqemu_add_wait_object()to avoid adding the same HANDLE twiceutil/main-loop.c | 11 +++++++---- 1 file changed, 7 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 };
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 400
Quoted 6 lines
util/main-loop.c +3
-0@@ -395,6 +395,9 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)if (w->events[i] == handle) { found =1 ; } +if (i ==MAXIMUM_WAIT_OBJECTS -1 ) { +break ; + }
Took me a while to realize this was protecting the body of the next if from out of bounds access. Can we redo this to make it explicit:
util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 401
Quoted 1 line
util/main-loop.c +0
-0if (found) {
if (found &&
i < (MAXIMUM_WAIT_OBJECTS - 1)) {util/main-loop.c void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) · line 403
Quoted 2 lines
util/main-loop.c +0
-0w->events[i] = w->events[i +1 ]; w->func[i] = w->func[i +1 ];
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|