Bug 994707 - Fix crash reporter writing submission events with CRLF line endings on windows. r=bsmedberg
authorSteven MacLeod <smacleod@mozilla.com>
Wed, 16 Jul 2014 15:47:57 -0400
changeset 216814 a469473e6a4387932d8717c8cc4b91f102e3aab7
parent 216813 d84feb1c0de36cc836ebcd17939abdeeda038879
child 216815 3b9f8506d2cf5a6fc30a61e8bc4d546aedd237a5
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs994707
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 994707 - Fix crash reporter writing submission events with CRLF line endings on windows. r=bsmedberg This introduces a new argument to UIOpenWrite to open the file in binary mode. We now write the submission events in binary mode so that LF characters will not be translated to CRLF on Windows.
toolkit/crashreporter/client/crashreporter.cpp
toolkit/crashreporter/client/crashreporter.h
toolkit/crashreporter/client/crashreporter_gtk_common.cpp
toolkit/crashreporter/client/crashreporter_osx.mm
toolkit/crashreporter/client/crashreporter_win.cpp
--- a/toolkit/crashreporter/client/crashreporter.cpp
+++ b/toolkit/crashreporter/client/crashreporter.cpp
@@ -200,17 +200,17 @@ static void WriteSubmissionEvent(Submiss
 {
   if (gEventsPath.empty()) {
     // If there is no path for writing the submission event, skip it.
     return;
   }
 
   string localId = GetDumpLocalID();
   string fpath = gEventsPath + UI_DIR_SEPARATOR + localId + "-submission";
-  ofstream* f = UIOpenWrite(fpath.c_str());
+  ofstream* f = UIOpenWrite(fpath.c_str(), false, true);
   time_t tm;
   time(&tm);
 
   if (f->is_open()) {
     *f << "crash.submission.1\n";
     *f << tm << "\n";
     *f << localId << "\n";
     *f << (result == Succeeded ? "true" : "false") << "\n";
--- a/toolkit/crashreporter/client/crashreporter.h
+++ b/toolkit/crashreporter/client/crashreporter.h
@@ -136,16 +136,18 @@ bool UIGetIniPath(std::string& path);
 bool UIGetSettingsPath(const std::string& vendor,
                        const std::string& product,
                        std::string& settingsPath);
 bool UIEnsurePathExists(const std::string& path);
 bool UIFileExists(const std::string& path);
 bool UIMoveFile(const std::string& oldfile, const std::string& newfile);
 bool UIDeleteFile(const std::string& oldfile);
 std::ifstream* UIOpenRead(const std::string& filename);
-std::ofstream* UIOpenWrite(const std::string& filename, bool append=false);
+std::ofstream* UIOpenWrite(const std::string& filename,
+                           bool append=false,
+                           bool binary=false);
 void UIPruneSavedDumps(const std::string& directory);
 
 #ifdef _MSC_VER
 # pragma warning( pop )
 #endif
 
 #endif
--- a/toolkit/crashreporter/client/crashreporter_gtk_common.cpp
+++ b/toolkit/crashreporter/client/crashreporter_gtk_common.cpp
@@ -434,14 +434,24 @@ bool UIDeleteFile(const string& file)
   return (unlink(file.c_str()) != -1);
 }
 
 std::ifstream* UIOpenRead(const string& filename)
 {
   return new std::ifstream(filename.c_str(), std::ios::in);
 }
 
-std::ofstream* UIOpenWrite(const string& filename, bool append) // append=false
+std::ofstream* UIOpenWrite(const string& filename,
+                           bool append, // append=false
+                           bool binary) // binary=false
 {
-  return new std::ofstream(filename.c_str(),
-                           append ? std::ios::out | std::ios::app
-                                  : std::ios::out);
+  std::ios_base::openmode mode = std::ios::out;
+
+  if (append) {
+    mode = mode | std::ios::app;
+  }
+
+  if (binary) {
+    mode = mode | std::ios::binary;
+  }
+
+  return new std::ofstream(filename.c_str(), mode);
 }
--- a/toolkit/crashreporter/client/crashreporter_osx.mm
+++ b/toolkit/crashreporter/client/crashreporter_osx.mm
@@ -882,14 +882,24 @@ bool UIDeleteFile(const string& file)
   return (unlink(file.c_str()) != -1);
 }
 
 std::ifstream* UIOpenRead(const string& filename)
 {
   return new std::ifstream(filename.c_str(), std::ios::in);
 }
 
-std::ofstream* UIOpenWrite(const string& filename, bool append) // append=false
+std::ofstream* UIOpenWrite(const string& filename,
+                           bool append, // append=false
+                           bool binary) // binary=false
 {
-  return new std::ofstream(filename.c_str(),
-                           append ? std::ios::out | std::ios::app
-                                  : std::ios::out);
+  std::ios_base::openmode mode = std::ios::out;
+
+  if (append) {
+    mode = mode | std::ios::app;
+  }
+
+  if (binary) {
+    mode = mode | std::ios::binary;
+  }
+
+  return new std::ofstream(filename.c_str(), mode);
 }
--- a/toolkit/crashreporter/client/crashreporter_win.cpp
+++ b/toolkit/crashreporter/client/crashreporter_win.cpp
@@ -1447,34 +1447,40 @@ ifstream* UIOpenRead(const string& filen
 #else   // GCC
   ifstream* file = new ifstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
                                 ios::in);
 #endif  // _MSC_VER >= 1400
 
   return file;
 }
 
-ofstream* UIOpenWrite(const string& filename, bool append) // append=false
+ofstream* UIOpenWrite(const string& filename,
+                      bool append, // append=false
+                      bool binary) // binary=false
 {
   // adapted from breakpad's src/common/windows/http_upload.cc
+  std::ios_base::openmode mode = ios::out;
+  if (append) {
+    mode = mode | ios::app;
+  }
+  if (binary) {
+    mode = mode | ios::binary;
+  }
 
-  // The "open" method on pre-MSVC8 ifstream implementations doesn't accept a
-  // wchar_t* filename, so use _wfopen directly in that case.  For VC8 and
-  // later, _wfopen has been deprecated in favor of _wfopen_s, which does
-  // not exist in earlier versions, so let the ifstream open the file itself.
+  // For VC8 and later, _wfopen has been deprecated in favor of _wfopen_s,
+  // which does not exist in earlier versions, so let the ifstream open the
+  // file itself.
 #if _MSC_VER >= 1400  // MSVC 2005/8
   ofstream* file = new ofstream();
-  file->open(UTF8ToWide(filename).c_str(), append ? ios::out | ios::app
-                                                  : ios::out);
+  file->open(UTF8ToWide(filename).c_str(), mode);
 #elif defined(_MSC_VER)
-  ofstream* file = new ofstream(_wfopen(UTF8ToWide(filename).c_str(),
-                                        append ? L"a" : L"w"));
+#error "Compiling with your version of MSVC is no longer supported."
 #else   // GCC
   ofstream* file = new ofstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
-                                append ? ios::out | ios::app : ios::out);
+                                mode);
 #endif  // _MSC_VER >= 1400
 
   return file;
 }
 
 struct FileData
 {
   FILETIME timestamp;