[PATCH 9/9] openvz: Remove strtok_r calls from openvzReadNetworkConf

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

 



Rather than rely on strtok_r calls, use virStringSplitCount in order
to process the conf variable. Coverity complains because it doesn't
know that the returned temp variable in openvzReadVPSConfigParam
should be non-NULL.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/openvz/openvz_conf.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 99ce95c..6562fcc 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -200,7 +200,9 @@ openvzReadNetworkConf(virDomainDefPtr def,
     int ret;
     virDomainNetDefPtr net = NULL;
     char *temp = NULL;
-    char *token, *saveptr = NULL;
+    char **tmp = NULL;
+    size_t ntmp = 0;
+    size_t i;
 
     /*parse routing network configuration*
      * Sample from config:
@@ -214,20 +216,23 @@ openvzReadNetworkConf(virDomainDefPtr def,
                        veid);
         goto error;
     } else if (ret > 0) {
-        token = strtok_r(temp, " ", &saveptr);
-        while (token != NULL) {
+        if (!(tmp = virStringSplitCount(temp, " ", 0, &ntmp)))
+            goto error;
+
+        for (i = 0; i < ntmp; i++) {
             if (VIR_ALLOC(net) < 0)
                 goto error;
 
             net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
-            if (virDomainNetAppendIPAddress(net, token, AF_UNSPEC, 0) < 0)
+            if (virDomainNetAppendIPAddress(net, tmp[i], AF_UNSPEC, 0) < 0)
                 goto error;
 
             if (VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net) < 0)
                 goto error;
-
-            token = strtok_r(NULL, " ", &saveptr);
         }
+        virStringFreeListCount(tmp, ntmp);
+        ntmp = 0;
+        tmp = NULL;
     }
 
     /*parse bridge devices*/
@@ -242,15 +247,17 @@ openvzReadNetworkConf(virDomainDefPtr def,
                        veid);
         goto error;
     } else if (ret > 0) {
-        token = strtok_r(temp, ";", &saveptr);
-        while (token != NULL) {
-            /*add new device to list*/
+        if (!(tmp = virStringSplitCount(temp, " ", 0, &ntmp)))
+            goto error;
+
+        for (i = 0; i < ntmp; i++) {
+            /* add new device to list */
             if (VIR_ALLOC(net) < 0)
                 goto error;
 
             net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
 
-            char *p = token;
+            char *p = tmp[i];
             char cpy_temp[32];
             int len;
 
@@ -313,21 +320,21 @@ openvzReadNetworkConf(virDomainDefPtr def,
                     }
                 }
                 p = ++next;
-            } while (p < token + strlen(token));
+            } while (p < tmp[i] + strlen(tmp[i]));
 
             if (VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net) < 0)
                 goto error;
-
-            token = strtok_r(NULL, ";", &saveptr);
         }
     }
 
     VIR_FREE(temp);
+    virStringFreeListCount(tmp, ntmp);
 
     return 0;
 
  error:
     VIR_FREE(temp);
+    virStringFreeListCount(tmp, ntmp);
     virDomainNetDefFree(net);
     return -1;
 }
-- 
2.5.5

--
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]