[libvirt] [PATCH] Check getenv("PATH") for NULL in virFindFileInPath
 
            Otherwise this will segfault if PATH is not defined. Reported by Emre Erenoglu --- src/util/util.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/src/util/util.c b/src/util/util.c index 34cfc21..445fd4e 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -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 -- 1.7.0.4
 
            On Thu, Jun 10, 2010 at 10:42:56PM +0200, Matthias Bolte wrote:
Otherwise this will segfault if PATH is not defined.
Reported by Emre Erenoglu --- src/util/util.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c index 34cfc21..445fd4e 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -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 -- 1.7.0.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
ACK Dave
 
            On Thu, Jun 10, 2010 at 10:42:56PM +0200, Matthias Bolte wrote:
Otherwise this will segfault if PATH is not defined.
Reported by Emre Erenoglu --- src/util/util.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c index 34cfc21..445fd4e 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -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
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
 
            2010/6/11 Daniel P. Berrange <berrange@redhat.com>:
On Thu, Jun 10, 2010 at 10:42:56PM +0200, Matthias Bolte wrote:
Otherwise this will segfault if PATH is not defined.
Reported by Emre Erenoglu --- src/util/util.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c index 34cfc21..445fd4e 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -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
ACK
Daniel
Thanks, pushed. Matthias
participants (3)
- 
                 Daniel P. Berrange Daniel P. Berrange
- 
                 Dave Allan Dave Allan
- 
                 Matthias Bolte Matthias Bolte