[libvirt] [PATCH] qemu: fix a crash when save file can't be opened

In qemuDomainSaveMemory, wrapperFd might be NULL and should be checked before calling virFileWrapperFdCatchError. Same in doCoreDump. Bug: https://bugzilla.redhat.com/show_bug.cgi?id=880919 --- src/qemu/qemu_driver.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c526f5f..7892293 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2906,7 +2906,8 @@ qemuDomainSaveMemory(struct qemud_driver *driver, cleanup: VIR_FORCE_CLOSE(fd); - virFileWrapperFdCatchError(wrapperFd); + if (wrapperFd) + virFileWrapperFdCatchError(wrapperFd); virFileWrapperFdFree(wrapperFd); VIR_FREE(xml); @@ -3362,7 +3363,8 @@ doCoreDump(struct qemud_driver *driver, cleanup: VIR_FORCE_CLOSE(fd); if (ret != 0) { - virFileWrapperFdCatchError(wrapperFd); + if (wrapperFd) + virFileWrapperFdCatchError(wrapperFd); unlink(path); } virFileWrapperFdFree(wrapperFd); -- 1.7.8.6

On 11/28/2012 09:08 AM, Ján Tomko wrote:
In qemuDomainSaveMemory, wrapperFd might be NULL and should be checked before calling virFileWrapperFdCatchError. Same in doCoreDump.
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=880919 --- src/qemu/qemu_driver.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c526f5f..7892293 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2906,7 +2906,8 @@ qemuDomainSaveMemory(struct qemud_driver *driver,
cleanup: VIR_FORCE_CLOSE(fd); - virFileWrapperFdCatchError(wrapperFd); + if (wrapperFd) + virFileWrapperFdCatchError(wrapperFd); virFileWrapperFdFree(wrapperFd); VIR_FREE(xml);
@@ -3362,7 +3363,8 @@ doCoreDump(struct qemud_driver *driver, cleanup: VIR_FORCE_CLOSE(fd); if (ret != 0) { - virFileWrapperFdCatchError(wrapperFd); + if (wrapperFd) + virFileWrapperFdCatchError(wrapperFd); unlink(path); } virFileWrapperFdFree(wrapperFd);
ACK && Pushed, Martin

In qemuDomainSaveMemory, wrapperFd might be NULL and should be checked before calling virFileWrapperFdCatchError. Same in doCoreDump.
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=880919 --- src/qemu/qemu_driver.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c526f5f..7892293 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2906,7 +2906,8 @@ qemuDomainSaveMemory(struct qemud_driver *driver,
cleanup: VIR_FORCE_CLOSE(fd); - virFileWrapperFdCatchError(wrapperFd); + if (wrapperFd) + virFileWrapperFdCatchError(wrapperFd);
Wouldn't it instead be easier to fix virFileWrapperFdCatchError() to tolerate incoming NULL (meaning there is no error to catch) than to adjust every caller?

This reverts 8927c0e qemu: fix a crash when save file can't be opened and allows virFileWrapperFdCatchError to be called with NULL instead. --- src/qemu/qemu_driver.c | 6 ++---- src/util/virfile.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d58656a..7e29608 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2908,8 +2908,7 @@ qemuDomainSaveMemory(struct qemud_driver *driver, cleanup: VIR_FORCE_CLOSE(fd); - if (wrapperFd) - virFileWrapperFdCatchError(wrapperFd); + virFileWrapperFdCatchError(wrapperFd); virFileWrapperFdFree(wrapperFd); VIR_FREE(xml); @@ -3365,8 +3364,7 @@ doCoreDump(struct qemud_driver *driver, cleanup: VIR_FORCE_CLOSE(fd); if (ret != 0) { - if (wrapperFd) - virFileWrapperFdCatchError(wrapperFd); + virFileWrapperFdCatchError(wrapperFd); unlink(path); } virFileWrapperFdFree(wrapperFd); diff --git a/src/util/virfile.c b/src/util/virfile.c index 9593151..c79ef04 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -369,7 +369,7 @@ virFileWrapperFdClose(virFileWrapperFdPtr wfd) void virFileWrapperFdCatchError(virFileWrapperFdPtr wfd) { - if (wfd->err_msg) + if (wfd && wfd->err_msg) VIR_WARN("iohelper reports: %s", wfd->err_msg); } -- 1.7.8.6

This reverts 8927c0e qemu: fix a crash when save file can't be opened and allows virFileWrapperFdCatchError to be called with NULL instead. --- src/qemu/qemu_driver.c | 6 ++---- src/util/virfile.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
ACK.

On 2012年11月28日 23:26, Eric Blake wrote:
This reverts 8927c0e qemu: fix a crash when save file can't be opened and allows virFileWrapperFdCatchError to be called with NULL instead. --- src/qemu/qemu_driver.c | 6 ++---- src/util/virfile.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
ACK.
Pushed.
participants (4)
-
Eric Blake
-
Ján Tomko
-
Martin Kletzander
-
Osier Yang