From 98354e362c94ab3053db45aad0c8e4ef352fcdee Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 24 Mar 2016 14:57:42 +0100 Subject: [PATCH] testutils: Adapt to highly unlikely case 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 --- tests/testutils.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/testutils.c b/tests/testutils.c index 2df4250bb6..d6cd1936d0 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -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;