]> xenbits.xensource.com Git - libvirt.git/commitdiff
testutils: Adapt to highly unlikely case
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Mar 2016 13:57:42 +0000 (14:57 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Mar 2016 16:35:14 +0000 (17:35 +0100)
Coverity pointed out that getenv("PATH") may return NULL. Well,
we check for that in virFindFileInPath() too. If this happens, we
will pass NULL into strstr(). Ouch.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tests/testutils.c

index 2df4250bb6f5561761f1e3f03349e297535db630..d6cd1936d0fb0a903de184784ac33a72e82337bd 100644 (file)
@@ -813,9 +813,16 @@ virTestSetEnvPath(void)
     const char *path = getenv("PATH");
     char *new_path = NULL;
 
-    if (strstr(path, abs_builddir) != path &&
-        (virAsprintf(&new_path, "%s:%s", abs_builddir, path) < 0 ||
-         setenv("PATH", new_path, 1) < 0))
+    if (path) {
+        if (strstr(path, abs_builddir) != path &&
+            virAsprintf(&new_path, "%s:%s", abs_builddir, path) < 0)
+            goto cleanup;
+    } else {
+        if (VIR_STRDUP(new_path, abs_builddir) < 0)
+            goto cleanup;
+    }
+
+    if (setenv("PATH", new_path, 1) < 0)
         goto cleanup;
 
     ret = 0;