diff options
author | Damien Martin-Guillerez <dmarting@google.com> | 2015-04-14 09:26:44 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2015-04-14 14:32:58 +0000 |
commit | e6459a9fd8ee191dc11ce56dc549d45d42226da7 (patch) | |
tree | d934bd8b86231f9f8a07c43b64eb03cffc313177 | |
parent | 809966dd8c046ab1c38f4055394f54caae2ee78b (diff) |
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
-rw-r--r-- | src/main/cpp/util/file.cc | 7 |
1 files 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<std::string> pieces = blaze_util::Split(path, ':'); for (auto piece : pieces) { if (piece.empty()) { |