From 8c0f5091f2322adebccb0c4f35c253fea08be8d3 Mon Sep 17 00:00:00 2001 From: Steven MacLeod Date: Wed, 16 Jul 2014 15:47:57 -0400 Subject: [PATCH] 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. --HG-- extra : rebase_source : 828d593503960c77bcb6baee69d23161c838d3f6 --- .../crashreporter/client/crashreporter.cpp | 2 +- toolkit/crashreporter/client/crashreporter.h | 4 ++- .../client/crashreporter_gtk_common.cpp | 18 ++++++++++--- .../crashreporter/client/crashreporter_osx.mm | 18 ++++++++++--- .../client/crashreporter_win.cpp | 26 ++++++++++++------- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/toolkit/crashreporter/client/crashreporter.cpp b/toolkit/crashreporter/client/crashreporter.cpp index aa5f5dd85549..980de4dc664a 100644 --- a/toolkit/crashreporter/client/crashreporter.cpp +++ b/toolkit/crashreporter/client/crashreporter.cpp @@ -205,7 +205,7 @@ static void WriteSubmissionEvent(SubmissionResult result, 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); diff --git a/toolkit/crashreporter/client/crashreporter.h b/toolkit/crashreporter/client/crashreporter.h index f3131c184a44..01acde3e8cb5 100644 --- a/toolkit/crashreporter/client/crashreporter.h +++ b/toolkit/crashreporter/client/crashreporter.h @@ -141,7 +141,9 @@ 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 diff --git a/toolkit/crashreporter/client/crashreporter_gtk_common.cpp b/toolkit/crashreporter/client/crashreporter_gtk_common.cpp index 4de33910407e..ff6249f0153a 100644 --- a/toolkit/crashreporter/client/crashreporter_gtk_common.cpp +++ b/toolkit/crashreporter/client/crashreporter_gtk_common.cpp @@ -439,9 +439,19 @@ 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); } diff --git a/toolkit/crashreporter/client/crashreporter_osx.mm b/toolkit/crashreporter/client/crashreporter_osx.mm index 10db019f612d..d80a99ce1478 100644 --- a/toolkit/crashreporter/client/crashreporter_osx.mm +++ b/toolkit/crashreporter/client/crashreporter_osx.mm @@ -887,9 +887,19 @@ 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); } diff --git a/toolkit/crashreporter/client/crashreporter_win.cpp b/toolkit/crashreporter/client/crashreporter_win.cpp index 3f2f597cf60f..62c2a6032af7 100644 --- a/toolkit/crashreporter/client/crashreporter_win.cpp +++ b/toolkit/crashreporter/client/crashreporter_win.cpp @@ -1452,24 +1452,30 @@ ifstream* UIOpenRead(const string& filename) 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;