]> xenbits.xensource.com Git - libvirt.git/commitdiff
Check getenv("PATH") for NULL in virFindFileInPath
authorMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 10 Jun 2010 19:52:33 +0000 (21:52 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 10 Jun 2010 20:39:11 +0000 (22:39 +0200)
Otherwise this will segfault if PATH is not defined.

Reported by Emre Erenoglu

src/util/util.c

index 34cfc212e8c90affa40be4671a61255d4260795f..445fd4e7d46660f07d909cdf17e9c8203799f21e 100644 (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