提交 98354e36 编写于 作者: M Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
上级 8c50daa1
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册