[PATCH 8/9] openvz: Remove need for strtok_r in openvzGenerateContainerVethName

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

 



Rather than use strtok_i to parse the VethName, use the virStringSplitCount
helper. The Coverity checker would "mark" that it's possible that the results
of the strtok_r may not be what's expected if openvzReadVPSConfigParam
returned a NULL (although logically it shouldn't, but Coverity got lost).

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/openvz/openvz_driver.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index f9a89cf..22dc333 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -798,20 +798,25 @@ openvzGenerateContainerVethName(int veid)
 {
     char *temp = NULL;
     char *name = NULL;
+    char **tmp = NULL;
+    size_t i;
+    size_t ntmp = 0;
 
     /* try to get line "^NETIF=..." from config */
     if (openvzReadVPSConfigParam(veid, "NETIF", &temp) <= 0) {
         ignore_value(VIR_STRDUP(name, "eth0"));
     } else {
-        char *saveptr = NULL;
-        char *s;
         int max = 0;
 
+        if (!(tmp = virStringSplitCount(temp, ";", 0, &ntmp)))
+            goto cleanup;
+
         /* get maximum interface number (actually, it is the last one) */
-        for (s = strtok_r(temp, ";", &saveptr); s; s = strtok_r(NULL, ";", &saveptr)) {
+        for (i = 0; i < ntmp; i++) {
             int x;
 
-            if (sscanf(s, "ifname=eth%d", &x) != 1) return NULL;
+            if (sscanf(tmp[i], "ifname=eth%d", &x) != 1)
+                goto cleanup;
             if (x > max) max = x;
         }
 
@@ -819,8 +824,9 @@ openvzGenerateContainerVethName(int veid)
         ignore_value(virAsprintf(&name, "eth%d", max + 1));
     }
 
+ cleanup:
     VIR_FREE(temp);
-
+    virStringFreeListCount(tmp, ntmp);
     return name;
 }
 
-- 
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]