]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: detect truncated file as invalid save image
authorEric Blake <eblake@redhat.com>
Fri, 16 Dec 2011 00:28:18 +0000 (17:28 -0700)
committerEric Blake <eblake@redhat.com>
Fri, 16 Dec 2011 15:29:31 +0000 (08:29 -0700)
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

index 725b5930df630301113d47ec320759f20393123a..0d99ce4c2f0e34483d688dfae7ab2bd26cbe0977 100644 (file)
@@ -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;