summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-05-29 17:50:29 (GMT)
committerGennadiy Civil <misterg@google.com>2019-05-30 03:35:59 (GMT)
commit899c082633dd13e3d053e2d46895faea12bfe074 (patch)
treea51d5d651086e0f07f0859373483ff1c8dccc498
parentf5edb4f542e155c75bc4b516f227911d99ec167c (diff)
downloadgoogletest-899c082633dd13e3d053e2d46895faea12bfe074.zip
googletest-899c082633dd13e3d053e2d46895faea12bfe074.tar.gz
googletest-899c082633dd13e3d053e2d46895faea12bfe074.tar.bz2
Googletest export
Add a safety nullptr check to catch the case where the /tmp file used for capturing a stream cannot be created. PiperOrigin-RevId: 250523012
-rw-r--r--CONTRIBUTING.md3
-rw-r--r--googletest/src/gtest-port.cc9
2 files changed, 10 insertions, 2 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4709e10..b52f8ee 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -20,8 +20,7 @@ instructions for how to sign and return it. Once we receive it, we'll be able to
accept your pull requests.
## Are you a Googler?
-If you are a Googler, plese make an attempt to submit an internal change rather than a GitHub Pull Request.
-If you are not able to submit an internal change a PR is acceptable as an alternative.
+If you are a Googler, you can either create an internal change or work on GitHub directly.
## Contributing A Patch
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc
index 4015a1c..74daaaa 100644
--- a/googletest/src/gtest-port.cc
+++ b/googletest/src/gtest-port.cc
@@ -1113,6 +1113,11 @@ class CapturedStream {
char name_template[] = "/tmp/captured_stream.XXXXXX";
# endif // GTEST_OS_LINUX_ANDROID
const int captured_fd = mkstemp(name_template);
+ if (captured_fd == -1) {
+ GTEST_LOG_(WARNING)
+ << "Failed to create tmp file " << name_template
+ << " for test; does the test have access to the /tmp directory?";
+ }
filename_ = name_template;
# endif // GTEST_OS_WINDOWS
fflush(nullptr);
@@ -1134,6 +1139,10 @@ class CapturedStream {
}
FILE* const file = posix::FOpen(filename_.c_str(), "r");
+ if (file == nullptr) {
+ GTEST_LOG_(FATAL) << "Failed to open tmp file " << filename_
+ << " for capturing stream.";
+ }
const std::string content = ReadEntireFile(file);
posix::FClose(file);
return content;