[libvirt] [PATCH] qemu: detect truncated file as invalid save image

If managed save fails at the right point in time, then the save image can end up with 0 bytes in length (no valid header), and our attempts in commit 55d88def to detect and skip invalid save files missed this case. * src/qemu/qemu_driver.c (qemuDomainSaveImageOpen): Also unlink empty file as corrupt. Reported by Dennis Householder. --- src/qemu/qemu_driver.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 725b593..0d99ce4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3852,6 +3852,15 @@ qemuDomainSaveImageOpen(struct qemud_driver *driver, goto error; if (saferead(fd, &header, sizeof(header)) != sizeof(header)) { + if (unlink_corrupt) { + if (VIR_CLOSE(fd) < 0 || unlink(path) < 0) { + virReportSystemError(errno, + _("cannot remove corrupt file: %s"), + path); + goto error; + } + return -3; + } qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read qemu header")); goto error; -- 1.7.7.4

On 2011年12月16日 08:42, Eric Blake wrote:
If managed save fails at the right point in time, then the save image can end up with 0 bytes in length (no valid header), and our attempts in commit 55d88def to detect and skip invalid save files missed this case.
* src/qemu/qemu_driver.c (qemuDomainSaveImageOpen): Also unlink empty file as corrupt. Reported by Dennis Householder. --- src/qemu/qemu_driver.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 725b593..0d99ce4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3852,6 +3852,15 @@ qemuDomainSaveImageOpen(struct qemud_driver *driver, goto error;
if (saferead(fd,&header, sizeof(header)) != sizeof(header)) { + if (unlink_corrupt) { + if (VIR_CLOSE(fd)< 0 || unlink(path)< 0) { + virReportSystemError(errno, + _("cannot remove corrupt file: %s"), + path); + goto error; + } + return -3; + } qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read qemu header")); goto error;
ACK

On 12/15/2011 08:37 PM, Osier Yang wrote:
On 2011年12月16日 08:42, Eric Blake wrote:
If managed save fails at the right point in time, then the save image can end up with 0 bytes in length (no valid header), and our attempts in commit 55d88def to detect and skip invalid save files missed this case.
* src/qemu/qemu_driver.c (qemuDomainSaveImageOpen): Also unlink empty file as corrupt. Reported by Dennis Householder.
ACK
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Osier Yang