[libvirt] [PATCH] vbox: avoid provoking assertions in VBoxSVC

Passing a NULL pointer to IMachine::delete virtualbox API causes VBoxSVC to raise an assertion. This patch passes an empty array instead. --- src/vbox/vbox_tmpl.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 68e3b05..be25828 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,7 +5294,8 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags) ((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - machine->vtbl->Delete(machine, 0, NULL, &progress); + vboxArray array = VBOX_ARRAY_INITIALIZER; + machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); # endif if (progress != NULL) { progress->vtbl->WaitForCompletion(progress, -1); -- 1.7.9.1

On 04/13/2012 07:04 AM, Jean-Baptiste Rouault wrote:
Passing a NULL pointer to IMachine::delete virtualbox API causes VBoxSVC to raise an assertion. This patch passes an empty array instead. --- src/vbox/vbox_tmpl.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 68e3b05..be25828 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,7 +5294,8 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - machine->vtbl->Delete(machine, 0, NULL, &progress); + vboxArray array = VBOX_ARRAY_INITIALIZER; + machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); # endif
ACK and Pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 04/17/2012 10:50 AM, Eric Blake wrote:
On 04/13/2012 07:04 AM, Jean-Baptiste Rouault wrote:
Passing a NULL pointer to IMachine::delete virtualbox API causes VBoxSVC to raise an assertion. This patch passes an empty array instead. --- src/vbox/vbox_tmpl.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 68e3b05..be25828 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,7 +5294,8 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - machine->vtbl->Delete(machine, 0, NULL, &progress); + vboxArray array = VBOX_ARRAY_INITIALIZER; + machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); # endif
ACK and Pushed.
Phooey. Now I'm getting compile failure: cc1: warnings being treated as errors In file included from vbox/vbox_V4_0.c:13: vbox/vbox_tmpl.c: In function 'vboxDomainUndefineFlags': vbox/vbox_tmpl.c:5298: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Commit 78345c68 makes at least gcc 4.1.2 on RHEL 5 complain: cc1: warnings being treated as errors In file included from vbox/vbox_V4_0.c:13: vbox/vbox_tmpl.c: In function 'vboxDomainUndefineFlags': vbox/vbox_tmpl.c:5298: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] * src/vbox/vbox_tmpl.c (vboxDomainUndefineFlags): Use union to avoid compiler warning. --- Pushing this under the build-breaker rule. src/vbox/vbox_tmpl.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index be25828..57c18a4 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,8 +5294,11 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags) ((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - vboxArray array = VBOX_ARRAY_INITIALIZER; - machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); + union { + vboxArray array; + IMedium *medium; + } u = { .array = VBOX_ARRAY_INITIALIZER }; + machine->vtbl->Delete(machine, 0, &u.medium, &progress); # endif if (progress != NULL) { progress->vtbl->WaitForCompletion(progress, -1); -- 1.7.7.6

Am 20. April 2012 01:36 schrieb Eric Blake <eblake@redhat.com>:
Commit 78345c68 makes at least gcc 4.1.2 on RHEL 5 complain:
cc1: warnings being treated as errors In file included from vbox/vbox_V4_0.c:13: vbox/vbox_tmpl.c: In function 'vboxDomainUndefineFlags': vbox/vbox_tmpl.c:5298: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
* src/vbox/vbox_tmpl.c (vboxDomainUndefineFlags): Use union to avoid compiler warning. ---
Pushing this under the build-breaker rule.
src/vbox/vbox_tmpl.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index be25828..57c18a4 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,8 +5294,11 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - vboxArray array = VBOX_ARRAY_INITIALIZER; - machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); + union { + vboxArray array; + IMedium *medium; + } u = { .array = VBOX_ARRAY_INITIALIZER }; + machine->vtbl->Delete(machine, 0, &u.medium, &progress); # endif if (progress != NULL) { progress->vtbl->WaitForCompletion(progress, -1);
Actually, NACK. As stated in the other mail, vboxArray is not castable to IMedium*. True, it silences the compiler any might even work by accident on XPCOM because VirtualBox might not touch the pointer beyond checking it for being non-NULL because the 0 tells it that it's an empty array. But still this is wrong and might crash on MSCOM. I might come up with a proper solution tomorrow. -- Matthias Bolte http://photron.blogspot.com

Am 20. April 2012 08:53 schrieb Matthias Bolte <matthias.bolte@googlemail.com>:
Am 20. April 2012 01:36 schrieb Eric Blake <eblake@redhat.com>:
Commit 78345c68 makes at least gcc 4.1.2 on RHEL 5 complain:
cc1: warnings being treated as errors In file included from vbox/vbox_V4_0.c:13: vbox/vbox_tmpl.c: In function 'vboxDomainUndefineFlags': vbox/vbox_tmpl.c:5298: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
* src/vbox/vbox_tmpl.c (vboxDomainUndefineFlags): Use union to avoid compiler warning. ---
Pushing this under the build-breaker rule.
src/vbox/vbox_tmpl.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index be25828..57c18a4 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,8 +5294,11 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - vboxArray array = VBOX_ARRAY_INITIALIZER; - machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); + union { + vboxArray array; + IMedium *medium; + } u = { .array = VBOX_ARRAY_INITIALIZER }; + machine->vtbl->Delete(machine, 0, &u.medium, &progress); # endif if (progress != NULL) { progress->vtbl->WaitForCompletion(progress, -1);
Actually, NACK. As stated in the other mail, vboxArray is not castable to IMedium*. True, it silences the compiler any might even work by accident on XPCOM because VirtualBox might not touch the pointer beyond checking it for being non-NULL because the 0 tells it that it's an empty array. But still this is wrong and might crash on MSCOM.
I might come up with a proper solution tomorrow.
Okay, looking at this in a bigger context shows that we already have a special case in place for this call for MSCOM that doesn't use vboxArray, because I didn't want to add a full vboxArray solution for this single case. XPCOM doesn't like being pass NULL for an array even if it's an empty array, according to Jean-Baptiste (I can not reproduce the problem). Anyway, I think the proper special case for this is to just a dummy IMedium* array not involving vboxArray at all. IMedium *array[] = { NULL }; machine->vtbl->Delete(machine, 0, array, &progress); See this patch https://www.redhat.com/archives/libvir-list/2012-April/msg01211.html -- Matthias Bolte http://photron.blogspot.com

Am 20. April 2012 01:07 schrieb Eric Blake <eblake@redhat.com>:
On 04/17/2012 10:50 AM, Eric Blake wrote:
On 04/13/2012 07:04 AM, Jean-Baptiste Rouault wrote:
Passing a NULL pointer to IMachine::delete virtualbox API causes VBoxSVC to raise an assertion. This patch passes an empty array instead. --- src/vbox/vbox_tmpl.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 68e3b05..be25828 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,7 +5294,8 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - machine->vtbl->Delete(machine, 0, NULL, &progress); + vboxArray array = VBOX_ARRAY_INITIALIZER; + machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); # endif
ACK and Pushed.
Actually, this is not how vboxArray is supposed to be used. vboxArray is a wrapper with specific implementations for MSCOM and XPCOM. You cannot just cast it to a VirtualBox API type.
Phooey. Now I'm getting compile failure:
cc1: warnings being treated as errors In file included from vbox/vbox_V4_0.c:13: vbox/vbox_tmpl.c: In function 'vboxDomainUndefineFlags': vbox/vbox_tmpl.c:5298: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
I think we need a new vboxArrayPass/Set function to get this right. I might have time to take care of this tomorrow, if nobody fixed it before then. -- Matthias Bolte http://photron.blogspot.com

Am 20. April 2012 08:48 schrieb Matthias Bolte <matthias.bolte@googlemail.com>:
Am 20. April 2012 01:07 schrieb Eric Blake <eblake@redhat.com>:
On 04/17/2012 10:50 AM, Eric Blake wrote:
On 04/13/2012 07:04 AM, Jean-Baptiste Rouault wrote:
Passing a NULL pointer to IMachine::delete virtualbox API causes VBoxSVC to raise an assertion. This patch passes an empty array instead. --- src/vbox/vbox_tmpl.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 68e3b05..be25828 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5294,7 +5294,8 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); # else - machine->vtbl->Delete(machine, 0, NULL, &progress); + vboxArray array = VBOX_ARRAY_INITIALIZER; + machine->vtbl->Delete(machine, 0, (IMedium**)&array, &progress); # endif
ACK and Pushed.
Actually, this is not how vboxArray is supposed to be used. vboxArray is a wrapper with specific implementations for MSCOM and XPCOM. You cannot just cast it to a VirtualBox API type.
Phooey. Now I'm getting compile failure:
cc1: warnings being treated as errors In file included from vbox/vbox_V4_0.c:13: vbox/vbox_tmpl.c: In function 'vboxDomainUndefineFlags': vbox/vbox_tmpl.c:5298: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
I think we need a new vboxArrayPass/Set function to get this right. I might have time to take care of this tomorrow, if nobody fixed it before then.
No, it much simpler than that, see https://www.redhat.com/archives/libvir-list/2012-April/msg01211.html -- Matthias Bolte http://photron.blogspot.com
participants (3)
-
Eric Blake
-
Jean-Baptiste Rouault
-
Matthias Bolte