Check getenv("PATH") for NULL in virFindFileInPath

Otherwise this will segfault if PATH is not defined.

Reported by Emre Erenoglu
This commit is contained in:
Matthias Bolte 2010-06-10 21:52:33 +02:00
parent b28a068b43
commit fc1da688c0

View File

@ -1213,6 +1213,7 @@ int virFileResolveLink(const char *linkpath,
*/
char *virFindFileInPath(const char *file)
{
char *path;
char pathenv[PATH_MAX];
char *penv = pathenv;
char *pathseg;
@ -1232,7 +1233,9 @@ char *virFindFileInPath(const char *file)
}
/* copy PATH env so we can tweak it */
if (virStrcpyStatic(pathenv, getenv("PATH")) == NULL)
path = getenv("PATH");
if (path == NULL || virStrcpyStatic(pathenv, path) == NULL)
return NULL;
/* for each path segment, append the file to search for and test for