[libvirt] [PATCH v2 2/6] openvz: Resolve Coverity FORWARD_NULL

John Ferlan jferlan at redhat.com
Fri Sep 25 16:31:41 UTC 2015


Coverity complains that strtok_r cannot be called if the first and third
parameters are NULL. On entry if the 'value' parameter is not checked for
being NULL before the VIR_STRDUP which will set the target to NULL if
the source (eg value) is NULL.  Thus add a check for NULL value.

NB: Although each of the callers to openvzParseBarrierLimit would only
make the call when 'value' was non-NULL, it seems that doesn't satisfy
the checker. The NULL check had to be in this funtion.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/openvz/openvz_conf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index fb8768a..e99b83c 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -135,10 +135,10 @@ openvzParseBarrierLimit(const char* value,
 {
     char *token;
     char *saveptr = NULL;
-    char *str;
+    char *str = NULL;
     int ret = -1;
 
-    if (VIR_STRDUP(str, value) < 0)
+    if (!value || VIR_STRDUP(str, value) < 0)
         goto error;
 
     token = strtok_r(str, ":", &saveptr);
@@ -396,7 +396,7 @@ openvzReadFSConf(virDomainDefPtr def,
     param = "DISKSPACE";
     ret = openvzReadVPSConfigParam(veid, param, &temp);
     if (ret > 0) {
-        if (openvzParseBarrierLimit(temp, &barrier, &limit)) {
+        if (openvzParseBarrierLimit(temp, &barrier, &limit) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Could not read '%s' from config for container %d"),
                            param, veid);
-- 
2.1.0




More information about the libvir-list mailing list