Commit dc04750a authored by finnur@chromium.org's avatar finnur@chromium.org

Revert 223610 "Set the printer info in crash reports using the c..."

Reverting due to buffer overflow reported on the Linux mem bot.
http://build.chromium.org/p/chromium.memory/builders/Linux%20ASAN%20Tests%20%283%29/builds/15489

> Set the printer info in crash reports using the crash key logging system.
> 
> BUG=77656
> R=jochen@chromium.org
> 
> Review URL: https://codereview.chromium.org/23604061

TBR=rsesek@chromium.org

Review URL: https://codereview.chromium.org/23503070

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223613 0039d316-1c4b-4281-b951-d872f2087c98
parent 2c84baa7
......@@ -1157,6 +1157,11 @@ void HandleCrashDump(const BreakpadInfo& info) {
// abcdef \r\n
// BOUNDARY \r\n
//
// zero to 4:
// Content-Disposition: form-data; name="prn-info-1" \r\n \r\n
// abcdefghijklmnopqrstuvwxyzabcdef \r\n
// BOUNDARY \r\n
//
// zero or one:
// Content-Disposition: form-data; name="num-switches" \r\n \r\n
// 5 \r\n
......@@ -1274,6 +1279,19 @@ void HandleCrashDump(const BreakpadInfo& info) {
writer.Flush();
}
unsigned printer_info_len =
my_strlen(child_process_logging::g_printer_info);
if (printer_info_len) {
static const char printer_info_msg[] = "prn-info-";
static const unsigned kMaxPrnInfoLen =
kMaxReportedPrinterRecords * child_process_logging::kPrinterInfoStrLen;
writer.AddPairDataInChunks(printer_info_msg, sizeof(printer_info_msg) - 1,
child_process_logging::g_printer_info,
std::min(printer_info_len, kMaxPrnInfoLen),
child_process_logging::kPrinterInfoStrLen,
true);
}
if (*child_process_logging::g_num_switches) {
writer.AddPairString("num-switches",
child_process_logging::g_num_switches);
......
......@@ -105,6 +105,7 @@ typedef NTSTATUS (WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle,
char* g_real_terminate_process_stub = NULL;
static size_t g_client_id_offset = 0;
static size_t g_printer_info_offset = 0;
static size_t g_num_switches_offset = 0;
static size_t g_switches_offset = 0;
static size_t g_dynamic_keys_offset = 0;
......@@ -457,6 +458,16 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& exe_path,
g_custom_entries->push_back(google_breakpad::CustomInfoEntry(
L"special", UTF16ToWide(special_build).c_str()));
// Add empty values for the prn_info-*. We'll put the actual values when we
// collect them at this location.
g_printer_info_offset = g_custom_entries->size();
// one-based index for the name suffix.
for (size_t i = 1; i <= kMaxReportedPrinterRecords; ++i) {
g_custom_entries->push_back(
google_breakpad::CustomInfoEntry(
base::StringPrintf(L"prn-info-%d", i).c_str(), L""));
}
// Read the id from registry. If reporting has never been enabled
// the result will be empty string. Its OK since when user enables reporting
// we will insert the new value at this location.
......@@ -642,6 +653,21 @@ extern "C" void __declspec(dllexport) __cdecl SetClientId(
google_breakpad::CustomInfoEntry::kValueMaxLength);
}
extern "C" void __declspec(dllexport) __cdecl SetPrinterInfo(
const wchar_t* printer_info) {
if (!g_custom_entries)
return;
std::vector<string16> info;
base::SplitString(printer_info, L';', &info);
DCHECK_LE(info.size(), kMaxReportedPrinterRecords);
info.resize(kMaxReportedPrinterRecords);
for (size_t i = 0; i < info.size(); ++i) {
base::wcslcpy((*g_custom_entries)[g_printer_info_offset + i].value,
info[i].c_str(),
google_breakpad::CustomInfoEntry::kValueMaxLength);
}
}
// NOTE: This function is used by SyzyASAN to annotate crash reports. If you
// change the name or signature of this function you will break SyzyASAN
// instrumented releases of Chrome. Please contact syzygy-team@chromium.org
......
......@@ -12,7 +12,7 @@
#include "base/metrics/histogram.h"
#include "base/values.h"
#include "chrome/browser/ui/webui/print_preview/print_preview_handler.h"
#include "chrome/common/crash_keys.h"
#include "chrome/common/child_process_logging.h"
#include "printing/backend/print_backend.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings.h"
......@@ -112,7 +112,7 @@ void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) {
void PrintSystemTaskProxy::GetPrinterCapabilities(
const std::string& printer_name) {
VLOG(1) << "Get printer capabilities start for " << printer_name;
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
print_backend_->GetPrinterDriverInfo(printer_name));
if (!print_backend_->IsValidPrinter(printer_name)) {
......
......@@ -25,6 +25,9 @@ static const size_t kMaxReportedVariationChunks = 15;
// limit of google_breakpad::CustomInfoEntry::kValueMaxLength.
static const size_t kMaxVariationChunkSize = 64;
// The maximum number of prn-info-* records.
static const size_t kMaxReportedPrinterRecords = 4;
// The maximum number of command line switches to include in the crash
// report's metadata. Note that the mini-dump itself will also contain the
// (original) command line arguments within the PEB.
......@@ -40,11 +43,15 @@ namespace child_process_logging {
extern char g_client_id[];
extern char g_num_switches[];
extern char g_num_variations[];
extern char g_printer_info[];
extern char g_switches[];
extern char g_variation_chunks[];
// Assume command line switches are less than 64 chars.
static const size_t kSwitchLen = 64;
// Assume printer info strings are less than 64 chars.
static const size_t kPrinterInfoStrLen = 64;
#endif
// Sets the Client ID that is used as GUID if a Chrome process crashes.
......@@ -54,6 +61,11 @@ void SetClientId(const std::string& client_id);
// id in |client_id| if it's known, an empty string otherwise.
std::string GetClientId();
// Sets the data on the printer to send along with crash reports. Data may be
// separated by ';' up to kMaxReportedPrinterRecords strings. Each substring
// would be cut to 63 chars.
void SetPrinterInfo(const char* printer_info);
// Sets the command line arguments to send along with crash reports to the
// values in |command_line|.
void SetCommandLine(const CommandLine* command_line);
......@@ -61,6 +73,21 @@ void SetCommandLine(const CommandLine* command_line);
// Initialize the list of experiment info to send along with crash reports.
void SetExperimentList(const std::vector<string16>& state);
// Set/clear information about currently accessed printer.
class ScopedPrinterInfoSetter {
public:
explicit ScopedPrinterInfoSetter(const std::string& printer_info) {
SetPrinterInfo(printer_info.c_str());
}
~ScopedPrinterInfoSetter() {
SetPrinterInfo("");
}
private:
DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfoSetter);
};
} // namespace child_process_logging
#if defined(OS_WIN)
......
......@@ -23,6 +23,7 @@ using base::debug::SetCrashKeyValue;
using base::debug::ClearCrashKey;
const char* kGuidParamName = "guid";
const char* kPrinterInfoNameFormat = "prn-info-%zu";
// Account for the terminating null character.
static const size_t kClientIdSize = 32 + 1;
......@@ -48,6 +49,20 @@ std::string GetClientId() {
return std::string(g_client_id);
}
void SetPrinterInfo(const char* printer_info) {
std::vector<std::string> info;
base::SplitString(printer_info, ';', &info);
info.resize(kMaxReportedPrinterRecords);
for (size_t i = 0; i < info.size(); ++i) {
std::string key = base::StringPrintf(kPrinterInfoNameFormat, i);
if (!info[i].empty()) {
SetCrashKeyValue(key, info[i]);
} else {
ClearCrashKey(key);
}
}
}
void SetCommandLine(const CommandLine* command_line) {
DCHECK(command_line);
if (!command_line)
......
......@@ -23,6 +23,8 @@ static const size_t kClientIdSize = 32 + 1;
// these strings to the browser.
char g_client_id[kClientIdSize];
char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = "";
static const size_t kNumSize = 32;
char g_num_switches[kNumSize] = "";
char g_num_variations[kNumSize] = "";
......@@ -51,6 +53,20 @@ std::string GetClientId() {
return std::string(g_client_id);
}
void SetPrinterInfo(const char* printer_info) {
std::string printer_info_str;
std::vector<std::string> info;
base::SplitString(printer_info, L';', &info);
DCHECK_LE(info.size(), kMaxReportedPrinterRecords);
for (size_t i = 0; i < info.size(); ++i) {
printer_info_str += info[i];
// Truncate long switches, align short ones with spaces to be trimmed later.
printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' ');
}
base::strlcpy(g_printer_info, printer_info_str.c_str(),
arraysize(g_printer_info));
}
void SetCommandLine(const CommandLine* command_line) {
const CommandLine::StringVector& argv = command_line->argv();
......
......@@ -22,6 +22,10 @@ namespace {
// exported in breakpad_win.cc: void __declspec(dllexport) __cdecl SetClientId.
typedef void (__cdecl *MainSetClientId)(const wchar_t*);
// exported in breakpad_win.cc:
// void __declspec(dllexport) __cdecl SetPrinterInfo.
typedef void (__cdecl *MainSetPrinterInfo)(const wchar_t*);
// exported in breakpad_win.cc:
// void __declspec(dllexport) __cdecl SetCommandLine2
typedef void (__cdecl *MainSetCommandLine)(const wchar_t**, size_t);
......@@ -86,6 +90,21 @@ std::string GetClientId() {
return std::string();
}
void SetPrinterInfo(const char* printer_info) {
static MainSetPrinterInfo set_printer_info = NULL;
// note: benign race condition on set_printer_info.
if (!set_printer_info) {
HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
if (!exe_module)
return;
set_printer_info = reinterpret_cast<MainSetPrinterInfo>(
GetProcAddress(exe_module, "SetPrinterInfo"));
if (!set_printer_info)
return;
}
(set_printer_info)(UTF8ToWide(printer_info).c_str());
}
void SetCommandLine(const CommandLine* command_line) {
static MainSetCommandLine set_command_line = NULL;
// note: benign race condition on set_command_line.
......
......@@ -6,7 +6,6 @@
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
......@@ -72,8 +71,6 @@ const char kGPURenderer[] = "gpu-gl-renderer";
const char kGPUGLVersion[] = "gpu-glver";
#endif
const char kPrinterInfo[] = "prn-info-%" PRIuS;
#if defined(OS_MACOSX)
namespace mac {
......@@ -163,20 +160,6 @@ size_t RegisterChromeCrashKeys() {
}
}
// Register the printer info.
{
static char formatted_keys[kPrinterInfoCount][sizeof(kPrinterInfo) + 1] =
{{ 0 }};
const size_t formatted_key_len = sizeof(formatted_keys[0]);
for (size_t i = 1; i <= kPrinterInfoCount; ++i) {
int n = base::snprintf(
formatted_keys[i], formatted_key_len, kPrinterInfo, i);
DCHECK_GT(n, 0);
base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize };
keys.push_back(crash_key);
}
}
return base::debug::InitCrashKeys(&keys.at(0), keys.size(),
kSingleChunkLength);
}
......@@ -197,23 +180,4 @@ void SetActiveExtensions(const std::set<std::string>& extensions) {
}
}
ScopedPrinterInfo::ScopedPrinterInfo(const base::StringPiece& data) {
std::vector<std::string> info;
base::SplitString(data.as_string(), ';', &info);
for (size_t i = 1; i <= kPrinterInfoCount; ++i) {
std::string key = base::StringPrintf(kPrinterInfo, i);
std::string value;
if (i < info.size())
value = info[i];
base::debug::SetCrashKeyValue(key, value);
}
}
ScopedPrinterInfo::~ScopedPrinterInfo() {
for (size_t i = 1; i <= kPrinterInfoCount; ++i) {
std::string key = base::StringPrintf(kPrinterInfo, i);
base::debug::ClearCrashKey(key);
}
}
} // namespace crash_keys
......@@ -24,17 +24,6 @@ size_t RegisterChromeCrashKeys();
// multiple because of process collapsing).
void SetActiveExtensions(const std::set<std::string>& extensions);
// Sets the printer info. Data should be separated by ';' up to
// kPrinterInfoCount substrings. Each substring will be truncated if necessary.
class ScopedPrinterInfo {
public:
explicit ScopedPrinterInfo(const base::StringPiece& data);
~ScopedPrinterInfo();
private:
DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfo);
};
// Crash Key Name Constants ////////////////////////////////////////////////////
// The product release/distribution channel.
......@@ -70,11 +59,6 @@ extern const char kGPURenderer[];
extern const char kGPUGLVersion[];
#endif
// The user's printers, up to kPrinterInfoCount. Should be set with
// ScopedPrinterInfo.
const size_t kPrinterInfoCount = 4;
extern const char kPrinterInfo[];
#if defined(OS_MACOSX)
namespace mac {
......
......@@ -25,8 +25,8 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/child_process_logging.h"
#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/common/crash_keys.h"
#include "chrome/service/cloud_print/cloud_print_helpers.h"
#include "grit/generated_resources.h"
#include "printing/backend/cups_helper.h"
......@@ -264,7 +264,7 @@ class PrinterWatcherCUPS
PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE{
scoped_refptr<printing::PrintBackend> print_backend(
printing::PrintBackend::CreateInstance(NULL));
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
print_backend->GetPrinterDriverInfo(printer_name_));
if (delegate_ != NULL)
StopWatching();
......@@ -595,7 +595,7 @@ bool PrintSystemCUPS::GetPrinterCapsAndDefaults(
}
// TODO(gene): Retry multiple times in case of error.
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
server_info->backend->GetPrinterDriverInfo(short_printer_name));
if (!server_info->backend->GetPrinterCapsAndDefaults(short_printer_name,
printer_info) ) {
......@@ -618,7 +618,7 @@ bool PrintSystemCUPS::GetJobDetails(const std::string& printer_name,
if (!server_info)
return false;
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
server_info->backend->GetPrinterDriverInfo(short_printer_name));
cups_job_t* jobs = NULL;
int num_jobs = GetJobs(&jobs, server_info->url, cups_encryption_,
......@@ -778,7 +778,7 @@ PlatformJobId PrintSystemCUPS::SpoolPrintJob(
if (!server_info)
return false;
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
server_info->backend->GetPrinterDriverInfo(printer_name));
// We need to store options as char* string for the duration of the
......
......@@ -18,7 +18,7 @@
#include "base/win/scoped_com_initializer.h"
#include "base/win/scoped_comptr.h"
#include "base/win/scoped_hdc.h"
#include "chrome/common/crash_keys.h"
#include "chrome/common/child_process_logging.h"
#include "chrome/service/service_process.h"
#include "chrome/service/service_utility_process_host.h"
#include "grit/generated_resources.h"
......@@ -170,7 +170,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate {
scoped_refptr<printing::PrintBackend> print_backend(
printing::PrintBackend::CreateInstance(NULL));
printer_info_ = print_backend->GetPrinterDriverInfo(printer_name);
crash_keys::ScopedPrinterInfo crash_key(printer_info_);
child_process_logging::ScopedPrinterInfoSetter prn_info(printer_info_);
delegate_ = delegate;
// An empty printer name means watch the current server, we need to pass
......@@ -203,7 +203,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate {
// base::ObjectWatcher::Delegate method
virtual void OnObjectSignaled(HANDLE object) {
crash_keys::ScopedPrinterInfo crash_key(printer_info_);
child_process_logging::ScopedPrinterInfoSetter prn_info(printer_info_);
DWORD change = 0;
FindNextPrinterChangeNotification(object, &change, NULL, NULL);
......@@ -370,7 +370,7 @@ class PrintSystemWin : public PrintSystem {
// TODO(gene): add tags handling.
scoped_refptr<printing::PrintBackend> print_backend(
printing::PrintBackend::CreateInstance(NULL));
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
print_backend->GetPrinterDriverInfo(printer_name));
return core_->Spool(print_ticket, print_data_file_path,
print_data_mime_type, printer_name, job_title,
......@@ -403,7 +403,7 @@ class PrintSystemWin : public PrintSystem {
JobSpooler::Delegate* delegate) {
scoped_refptr<printing::PrintBackend> print_backend(
printing::PrintBackend::CreateInstance(NULL));
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
print_backend->GetPrinterDriverInfo(printer_name));
if (delegate_) {
// We are already in the process of printing.
......@@ -792,7 +792,7 @@ bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) {
bool PrintSystemWin::ValidatePrintTicket(
const std::string& printer_name,
const std::string& print_ticket_data) {
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
print_backend_->GetPrinterDriverInfo(printer_name));
printing::ScopedXPSInitializer xps_initializer;
if (!xps_initializer.initialized()) {
......@@ -833,7 +833,7 @@ bool PrintSystemWin::ValidatePrintTicket(
bool PrintSystemWin::GetJobDetails(const std::string& printer_name,
PlatformJobId job_id,
PrintJobDetails *job_details) {
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
print_backend_->GetPrinterDriverInfo(printer_name));
DCHECK(job_details);
printing::ScopedPrinterHandle printer_handle;
......
......@@ -54,7 +54,7 @@
#endif // defined(OS_WIN) || defined(OS_MACOSX)
#if defined(ENABLE_FULL_PRINTING)
#include "chrome/common/crash_keys.h"
#include "chrome/common/child_process_logging.h"
#include "printing/backend/print_backend.h"
#endif
......@@ -504,7 +504,7 @@ void ChromeContentUtilityClient::OnGetPrinterCapsAndDefaults(
printing::PrintBackend::CreateInstance(NULL);
printing::PrinterCapsAndDefaults printer_info;
crash_keys::ScopedPrinterInfo crash_key(
child_process_logging::ScopedPrinterInfoSetter prn_info(
print_backend->GetPrinterDriverInfo(printer_name));
if (print_backend->GetPrinterCapsAndDefaults(printer_name, &printer_info)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment