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
This commit is contained in:
Steven MacLeod 2014-07-16 15:47:57 -04:00
Родитель 1e3f120dc8
Коммит 8c0f5091f2
5 изменённых файлов: 48 добавлений и 20 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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;