]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Add error checking to virDomainSnapshotDiskDefFormat
authorJohn Ferlan <jferlan@redhat.com>
Wed, 8 Nov 2017 12:13:20 +0000 (07:13 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 19 Apr 2018 18:23:39 +0000 (14:23 -0400)
Commit id '43f2ccdc' called virDomainDiskSourceDefFormatInternal
rather than formatting the the disk source inline. However, it
did not handle the case where the helper failed. Over time the
helper has been renamed to virDomainDiskSourceFormat. Similar to
other consumers, if virDomainDiskSourceFormat fails, then the
formatting could be off, so it's better to fail than to continue
on with some possibly bad data. Alter the function and the caller
to check status and jump to error in that case.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/snapshot_conf.c

index d7b086242bd30e7ed984a29aa2dd01582d298e73..787c3d0feb5452a97db16d4e99fcfde032a73664 100644 (file)
@@ -662,7 +662,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
     return ret;
 }
 
-static void
+static int
 virDomainSnapshotDiskDefFormat(virBufferPtr buf,
                                virDomainSnapshotDiskDefPtr disk,
                                virDomainXMLOptionPtr xmlopt)
@@ -670,7 +670,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
     int type = disk->src->type;
 
     if (!disk->name)
-        return;
+        return 0;
 
     virBufferEscapeString(buf, "<disk name='%s'", disk->name);
     if (disk->snapshot > 0)
@@ -679,7 +679,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
 
     if (!disk->src->path && disk->src->format == 0) {
         virBufferAddLit(buf, "/>\n");
-        return;
+        return 0;
     }
 
     virBufferAsprintf(buf, " type='%s'>\n", virStorageTypeToString(type));
@@ -688,10 +688,12 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
     if (disk->src->format > 0)
         virBufferEscapeString(buf, "<driver type='%s'/>\n",
                               virStorageFileFormatTypeToString(disk->src->format));
-    virDomainDiskSourceFormat(buf, disk->src, 0, 0, xmlopt);
+    if (virDomainDiskSourceFormat(buf, disk->src, 0, 0, xmlopt) < 0)
+        return -1;
 
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</disk>\n");
+    return 0;
 }
 
 
@@ -741,8 +743,10 @@ virDomainSnapshotDefFormat(const char *domain_uuid,
     if (def->ndisks) {
         virBufferAddLit(&buf, "<disks>\n");
         virBufferAdjustIndent(&buf, 2);
-        for (i = 0; i < def->ndisks; i++)
-            virDomainSnapshotDiskDefFormat(&buf, &def->disks[i], xmlopt);
+        for (i = 0; i < def->ndisks; i++) {
+            if (virDomainSnapshotDiskDefFormat(&buf, &def->disks[i], xmlopt) < 0)
+                goto error;
+        }
         virBufferAdjustIndent(&buf, -2);
         virBufferAddLit(&buf, "</disks>\n");
     }