[libvirt] PATCH: Fix NULL checks in openvz driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim pointed out some places where the openvz driver could deference some
NULs, so this patch fixes them


Daniel

Index: src/openvz_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_driver.c,v
retrieving revision 1.46
diff -u -p -r1.46 openvz_driver.c
--- src/openvz_driver.c	5 Sep 2008 15:00:14 -0000	1.46
+++ src/openvz_driver.c	5 Sep 2008 15:11:34 -0000
@@ -276,7 +276,7 @@ static char *openvzDomainDumpXML(virDoma
 static int openvzDomainShutdown(virDomainPtr dom) {
     struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
     virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid);
-    const char *prog[] = {VZCTL, "--quiet", "stop", vm->def->name, NULL};
+    const char *prog[] = {VZCTL, "--quiet", "stop", NULL /* name */, NULL};
 
     if (!vm) {
         openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
@@ -290,6 +290,7 @@ static int openvzDomainShutdown(virDomai
         return -1;
     }
 
+    prog[3] = vm->def->name;
     if (virRun(dom->conn, prog, NULL) < 0)
         return -1;
 
@@ -303,7 +304,7 @@ static int openvzDomainReboot(virDomainP
                               unsigned int flags ATTRIBUTE_UNUSED) {
     struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
     virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid);
-    const char *prog[] = {VZCTL, "--quiet", "restart", vm->def->name, NULL};
+    const char *prog[] = {VZCTL, "--quiet", "restart", NULL /* name */, NULL};
 
     if (!vm) {
         openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
@@ -317,6 +318,7 @@ static int openvzDomainReboot(virDomainP
         return -1;
     }
 
+    prog[3] = vm->def->name;
     if (virRun(dom->conn, prog, NULL) < 0)
         return -1;
 
@@ -581,7 +583,7 @@ openvzDomainCreate(virDomainPtr dom)
 {
     struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
     virDomainObjPtr vm = virDomainFindByName(driver->domains, dom->name);
-    const char *prog[] = {VZCTL, "--quiet", "start", vm->def->name, NULL };
+    const char *prog[] = {VZCTL, "--quiet", "start", NULL /* name */, NULL };
 
     if (!vm) {
         openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
@@ -595,6 +597,7 @@ openvzDomainCreate(virDomainPtr dom)
         return -1;
     }
 
+    prog[3] = vm->def->name;
     if (virRun(dom->conn, prog, NULL) < 0) {
         openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
                _("Could not exec %s"), VZCTL);
@@ -614,7 +617,7 @@ openvzDomainUndefine(virDomainPtr dom)
     virConnectPtr conn= dom->conn;
     struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
     virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid);
-    const char *prog[] = { VZCTL, "--quiet", "destroy", vm->def->name, NULL };
+    const char *prog[] = { VZCTL, "--quiet", "destroy", NULL /* name */, NULL };
 
     if (!vm) {
         openvzError(conn, VIR_ERR_INVALID_DOMAIN, _("no domain with matching uuid"));
@@ -626,6 +629,7 @@ openvzDomainUndefine(virDomainPtr dom)
         return -1;
     }
 
+    prog[3] = vm->def->name;
     if (virRun(conn, prog, NULL) < 0) {
         openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                _("Could not exec %s"), VZCTL);
@@ -643,7 +647,7 @@ openvzDomainSetAutostart(virDomainPtr do
     virConnectPtr conn= dom->conn;
     struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
     virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid);
-    const char *prog[] = { VZCTL, "--quiet", "set", vm->def->name,
+    const char *prog[] = { VZCTL, "--quiet", "set", NULL /* name */,
                            "--onboot", autostart ? "yes" : "no",
                            "--save", NULL };
 
@@ -652,6 +656,7 @@ openvzDomainSetAutostart(virDomainPtr do
         return -1;
     }
 
+    prog[3] = vm->def->name;
     if (virRun(conn, prog, NULL) < 0) {
         openvzError(conn, VIR_ERR_INTERNAL_ERROR, _("Could not exec %s"), VZCTL);
         return -1;
@@ -704,16 +709,9 @@ static int openvzDomainSetVcpus(virDomai
     struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
     virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid);
     char   str_vcpus[32];
-    const char *prog[] = { VZCTL, "--quiet", "set", vm->def->name,
+    const char *prog[] = { VZCTL, "--quiet", "set", NULL /* name */,
                            "--cpus", str_vcpus, "--save", NULL };
-    snprintf(str_vcpus, 31, "%d", nvcpus);
-    str_vcpus[31] = '\0';
 
-    if (nvcpus <= 0) {
-        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
-                    _("VCPUs should be >= 1"));
-        return -1;
-    }
 
     if (!vm) {
         openvzError(conn, VIR_ERR_INVALID_DOMAIN,
@@ -721,6 +719,16 @@ static int openvzDomainSetVcpus(virDomai
         return -1;
     }
 
+    if (nvcpus <= 0) {
+        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+                    _("VCPUs should be >= 1"));
+        return -1;
+    }
+
+    snprintf(str_vcpus, 31, "%d", nvcpus);
+    str_vcpus[31] = '\0';
+
+    prog[3] = vm->def->name;
     if (virRun(conn, prog, NULL) < 0) {
         openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                     _("Could not exec %s"), VZCTL);

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]