]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: avoid null deref on qemu-img failure
authorEric Blake <eblake@redhat.com>
Fri, 21 Oct 2011 21:34:34 +0000 (15:34 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 26 Oct 2011 16:58:00 +0000 (10:58 -0600)
Detected by Coverity.  Only possible if qemu-img gives bogus output,
but we might as well be robust.

* src/storage/storage_backend.c
(virStorageBackendQEMUImgBackingFormat): Check for strstr failure.

src/storage/storage_backend.c

index 64c35c2bf3d46cd823c4f18d27364e3011183083..93c98d6cc9ea511efdf865cfb443b36e149dd904 100644 (file)
@@ -631,8 +631,13 @@ static int virStorageBackendQEMUImgBackingFormat(const char *qemuimg)
     if (virCommandRun(cmd, &exitstatus) < 0)
         goto cleanup;
 
-    start = strstr(help, " create ");
-    end = strstr(start, "\n");
+    if ((start = strstr(help, " create ")) == NULL ||
+        (end = strstr(start, "\n")) == NULL) {
+        virStorageReportError(VIR_ERR_INTERNAL_ERROR,
+                              _("unable to parse qemu-img output '%s'"),
+                              help);
+        goto cleanup;
+    }
     if (((tmp = strstr(start, "-F fmt")) && tmp < end) ||
         ((tmp = strstr(start, "-F backing_fmt")) && tmp < end))
         ret = QEMU_IMG_BACKING_FORMAT_FLAG;