UserCollector: only create meta file if payload write succeeds
This avoids creating meta files that are referencing a non-existant payload
which can block crash sending.
BUG=chromium:338977
TEST=Running unit tests locally did succeed.
Change-Id: Ia7039e679150490571d57a0960e984590905ee52
Reviewed-on: https://chromium-review.googlesource.com/199060
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
diff --git a/crash_reporter/user_collector.cc b/crash_reporter/user_collector.cc
index f6841e6..78f5482 100644
--- a/crash_reporter/user_collector.cc
+++ b/crash_reporter/user_collector.cc
@@ -192,6 +192,8 @@
LOG(ERROR) << "Could not even get log directory; out of space?";
return;
}
+ AddCrashMetaData("sig", kCollectionErrorSignature);
+ AddCrashMetaData("error_type", GetErrorTypeSignature(error_type));
std::string dump_basename = FormatDumpBasename(exec, time(NULL), pid);
std::string error_log = chromeos::GetLog();
FilePath diag_log_path = GetCrashPath(crash_path, dump_basename, "diaglog");
@@ -210,9 +212,10 @@
// We must use WriteNewFile instead of file_util::WriteFile as we do
// not want to write with root access to a symlink that an attacker
// might have created.
- WriteNewFile(log_path, error_log.data(), error_log.length());
- AddCrashMetaData("sig", kCollectionErrorSignature);
- AddCrashMetaData("error_type", GetErrorTypeSignature(error_type));
+ if (WriteNewFile(log_path, error_log.data(), error_log.length()) < 0) {
+ LOG(ERROR) << "Error writing new file " << log_path.value();
+ return;
+ }
WriteCrashMetaData(meta_path, exec, log_path.value());
}