зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
1e3f120dc8
Коммит
8c0f5091f2
|
@ -205,7 +205,7 @@ static void WriteSubmissionEvent(SubmissionResult result,
|
||||||
|
|
||||||
string localId = GetDumpLocalID();
|
string localId = GetDumpLocalID();
|
||||||
string fpath = gEventsPath + UI_DIR_SEPARATOR + localId + "-submission";
|
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_t tm;
|
||||||
time(&tm);
|
time(&tm);
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,9 @@ bool UIFileExists(const std::string& path);
|
||||||
bool UIMoveFile(const std::string& oldfile, const std::string& newfile);
|
bool UIMoveFile(const std::string& oldfile, const std::string& newfile);
|
||||||
bool UIDeleteFile(const std::string& oldfile);
|
bool UIDeleteFile(const std::string& oldfile);
|
||||||
std::ifstream* UIOpenRead(const std::string& filename);
|
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);
|
void UIPruneSavedDumps(const std::string& directory);
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
|
@ -439,9 +439,19 @@ std::ifstream* UIOpenRead(const string& filename)
|
||||||
return new std::ifstream(filename.c_str(), std::ios::in);
|
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(),
|
std::ios_base::openmode mode = std::ios::out;
|
||||||
append ? std::ios::out | std::ios::app
|
|
||||||
: 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);
|
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(),
|
std::ios_base::openmode mode = std::ios::out;
|
||||||
append ? std::ios::out | std::ios::app
|
|
||||||
: 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;
|
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
|
// 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
|
// For VC8 and later, _wfopen has been deprecated in favor of _wfopen_s,
|
||||||
// wchar_t* filename, so use _wfopen directly in that case. For VC8 and
|
// which does not exist in earlier versions, so let the ifstream open the
|
||||||
// later, _wfopen has been deprecated in favor of _wfopen_s, which does
|
// file itself.
|
||||||
// not exist in earlier versions, so let the ifstream open the file itself.
|
|
||||||
#if _MSC_VER >= 1400 // MSVC 2005/8
|
#if _MSC_VER >= 1400 // MSVC 2005/8
|
||||||
ofstream* file = new ofstream();
|
ofstream* file = new ofstream();
|
||||||
file->open(UTF8ToWide(filename).c_str(), append ? ios::out | ios::app
|
file->open(UTF8ToWide(filename).c_str(), mode);
|
||||||
: ios::out);
|
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
ofstream* file = new ofstream(_wfopen(UTF8ToWide(filename).c_str(),
|
#error "Compiling with your version of MSVC is no longer supported."
|
||||||
append ? L"a" : L"w"));
|
|
||||||
#else // GCC
|
#else // GCC
|
||||||
ofstream* file = new ofstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
|
ofstream* file = new ofstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
|
||||||
append ? ios::out | ios::app : ios::out);
|
mode);
|
||||||
#endif // _MSC_VER >= 1400
|
#endif // _MSC_VER >= 1400
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче