From e6459a9fd8ee191dc11ce56dc549d45d42226da7 Mon Sep 17 00:00:00 2001 From: Damien Martin-Guillerez Date: Tue, 14 Apr 2015 09:26:44 +0000 Subject: Check that getenv() returns non-null in blaze::Which() getenv() returns value was not checked for non-null result and it led to exception raised at runtime on some corner case (see bug #113). -- MOS_MIGRATED_REVID=91071694 --- src/main/cpp/util/file.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/cpp/util/file.cc b/src/main/cpp/util/file.cc index 86181196e5..8e76609484 100644 --- a/src/main/cpp/util/file.cc +++ b/src/main/cpp/util/file.cc @@ -74,12 +74,13 @@ string JoinPath(const string &path1, const string &path2) { } string Which(const string &executable) { - string path(getenv("PATH")); - if (path.empty()) { + char *path_cstr = getenv("PATH"); + if (path_cstr == NULL || path_cstr[0] == '\0') { die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "Could not get PATH to find %s", executable.c_str()); + "Could not get PATH to find %s", executable.c_str()); } + string path(path_cstr); std::vector pieces = blaze_util::Split(path, ':'); for (auto piece : pieces) { if (piece.empty()) { -- cgit v1.2.3