From c83c3e9e5c539f32aa5da08f51c418b2c24e2e47 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 21 Oct 2008 17:15:53 +0000 Subject: [PATCH] While doing on this patch series, I mistakenly added a bogus piece of storage XML to libvirtd, which was saved in /etc/libvirt/storage. On subsequent stop/start of libvirtd, because of another bug , an error wasn't being set properly in an error path, so libvirtd was SEGV'ing in storage_conf.c:virStoragePoolObjLoad when trying to dereference the NULL err returned from virGetLastError(). Make this more robust against errors by always doing "err ? err->message : NULL" in the printf. I looked around the tree and found a couple of other places that weren't guarded, so this patch fixes them as well. Signed-off-by: Chris Lalancette --- ChangeLog | 6 ++++++ src/network_driver.c | 3 ++- src/qemu_driver.c | 3 ++- src/storage_conf.c | 2 +- src/storage_driver.c | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3b85dac8c..eefc6664ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Oct 21 19:13:00 CEST 2008 Chris Lalancette + * src/qemu_driver.c src/storage_conf.c src/network_driver.c + src/storage_driver.c: Shore up the uses of virGetLastError() so that + if a path forgets to set a virError, we don't crash while trying + to dereference the NULL pointer to print out. + Tue Oct 21 09:19:24 PDT 2008 Dan Smith * src/cgroup.c src/cgroup.h: Add function to allow major device range * src/lxc_container.h src/controller.c: Fix cgroup initialization diff --git a/src/network_driver.c b/src/network_driver.c index 411cfde298..f483a258ab 100644 --- a/src/network_driver.c +++ b/src/network_driver.c @@ -98,7 +98,8 @@ networkAutostartConfigs(struct network_driver *driver) { networkStartNetworkDaemon(NULL, driver, driver->networks.objs[i]) < 0) { virErrorPtr err = virGetLastError(); networkLog(NETWORK_ERR, _("Failed to autostart network '%s': %s\n"), - driver->networks.objs[i]->def->name, err->message); + driver->networks.objs[i]->def->name, + err ? err->message : NULL); } } } diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 59d7166a61..34f743b684 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -136,7 +136,8 @@ qemudAutostartConfigs(struct qemud_driver *driver) { qemudStartVMDaemon(NULL, driver, driver->domains.objs[i], NULL) < 0) { virErrorPtr err = virGetLastError(); qemudLog(QEMUD_ERR, _("Failed to autostart VM '%s': %s\n"), - driver->domains.objs[i]->def->name, err->message); + driver->domains.objs[i]->def->name, + err ? err->message : NULL); } } } diff --git a/src/storage_conf.c b/src/storage_conf.c index db56b3c79a..23e7538f0c 100644 --- a/src/storage_conf.c +++ b/src/storage_conf.c @@ -1043,7 +1043,7 @@ virStoragePoolObjLoad(virConnectPtr conn, if (!(def = virStoragePoolDefParse(NULL, xml, file))) { virErrorPtr err = virGetLastError(); virStorageLog("Error parsing storage pool config '%s' : %s", - path, err->message); + path, err ? err->message : NULL); return NULL; } diff --git a/src/storage_driver.c b/src/storage_driver.c index e0d97e1fb1..0773821070 100644 --- a/src/storage_driver.c +++ b/src/storage_driver.c @@ -232,7 +232,7 @@ storageDriverShutdown(void) { backend->stopPool(NULL, pool) < 0) { virErrorPtr err = virGetLastError(); storageLog("Failed to stop storage pool '%s': %s", - pool->def->name, err->message); + pool->def->name, err ? err->message : NULL); } virStoragePoolObjClearVols(pool); }