[libvirt] [PATCH] umlAutostartDomain: avoid NULL-deref upon virGetLastError failure

Another...
From 09579adb73f04c5b940ad28cdfc242cff0726e0e Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 14:38:14 +0200 Subject: [PATCH] umlAutostartDomain: avoid NULL-deref upon virGetLastError failure
* src/uml/uml_driver.c (umlAutostartDomain): Handle a NULL return from virGetLastError. --- src/uml/uml_driver.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 63fe808..ffb87c8 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -157,7 +157,7 @@ umlAutostartDomain(void *payload, const char *name ATTRIBUTE_UNUSED, void *opaqu if (umlStartVMDaemon(data->conn, data->driver, vm) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart VM '%s': %s"), - vm->def->name, err->message); + vm->def->name, err ? err->message : ""); } } virDomainObjUnlock(vm); -- 1.7.1.250.g7d1e8

On 05/17/2010 06:38 AM, Jim Meyering wrote:
Another...
From 09579adb73f04c5b940ad28cdfc242cff0726e0e Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 14:38:14 +0200 Subject: [PATCH] umlAutostartDomain: avoid NULL-deref upon virGetLastError failure
* src/uml/uml_driver.c (umlAutostartDomain): Handle a NULL return from virGetLastError. --- src/uml/uml_driver.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 63fe808..ffb87c8 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -157,7 +157,7 @@ umlAutostartDomain(void *payload, const char *name ATTRIBUTE_UNUSED, void *opaqu if (umlStartVMDaemon(data->conn, data->driver, vm) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart VM '%s': %s"), - vm->def->name, err->message); + vm->def->name, err ? err->message : "");
That looks awkward to end with a trailing space. Might it be better to use: err ? err->message : _("unknown reason") At any rate, ACK that this fixes a potential NULL deref. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Eric Blake wrote:
On 05/17/2010 06:38 AM, Jim Meyering wrote:
Another...
From 09579adb73f04c5b940ad28cdfc242cff0726e0e Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 14:38:14 +0200 Subject: [PATCH] umlAutostartDomain: avoid NULL-deref upon virGetLastError failure
* src/uml/uml_driver.c (umlAutostartDomain): Handle a NULL return from virGetLastError. --- src/uml/uml_driver.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 63fe808..ffb87c8 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -157,7 +157,7 @@ umlAutostartDomain(void *payload, const char *name ATTRIBUTE_UNUSED, void *opaqu if (umlStartVMDaemon(data->conn, data->driver, vm) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart VM '%s': %s"), - vm->def->name, err->message); + vm->def->name, err ? err->message : "");
That looks awkward to end with a trailing space. Might it be better to use:
err ? err->message : _("unknown reason")
At any rate, ACK that this fixes a potential NULL deref.
That's a good point. I considered going one step further and changing virGetLastError so that it never returns NULL, instead returning a pointer to a static buffer where err->message is something like "internal failure". Otherwise, many uses of virGetLastError have to use the same awkward idiom: err ? err->message : "..." If no one objects to such a change, I'll add it to my low-priority list.

On 05/17/2010 09:09 AM, Jim Meyering wrote:
That looks awkward to end with a trailing space. Might it be better to use:
err ? err->message : _("unknown reason")
At any rate, ACK that this fixes a potential NULL deref.
That's a good point. I considered going one step further and changing virGetLastError so that it never returns NULL, instead returning a pointer to a static buffer where err->message is something like "internal failure".
Otherwise, many uses of virGetLastError have to use the same awkward idiom:
err ? err->message : "..."
If no one objects to such a change, I'll add it to my low-priority list.
Or even to my list, since I have a pending series on virterror.c cleanups. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Eric Blake wrote:
On 05/17/2010 09:09 AM, Jim Meyering wrote:
That looks awkward to end with a trailing space. Might it be better to use:
err ? err->message : _("unknown reason")
At any rate, ACK that this fixes a potential NULL deref.
That's a good point.
However, considering there are 20 others just like it, and in the spirit of keeping this fix minimal, I've pushed it as-is.
I considered going one step further and changing virGetLastError so that it never returns NULL, instead returning a pointer to a static buffer where err->message is something like "internal failure". ...
participants (2)
-
Eric Blake
-
Jim Meyering