From 62e22cbfe72cf7d6784210516928ed445880b158 Mon Sep 17 00:00:00 2001 From: "thestig@google.com" Date: Tue, 2 Jun 2009 00:35:47 +0000 Subject: Generate GUIDs for users who wish to upload crash reports. Include it in crash reports. BUG=none TEST=none Review URL: http://codereview.chromium.org/118096 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17372 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/breakpad_linux.cc | 58 ++++++++++++++++++---- chrome/app/breakpad_linux.h | 7 ++- chrome/browser/google_update_settings_linux.cc | 29 +++++++++-- .../render_crash_handler_host_linux.cc | 17 ++++--- 4 files changed, 89 insertions(+), 22 deletions(-) diff --git a/chrome/app/breakpad_linux.cc b/chrome/app/breakpad_linux.cc index 0985bd4..0712241 100644 --- a/chrome/app/breakpad_linux.cc +++ b/chrome/app/breakpad_linux.cc @@ -36,8 +36,11 @@ static void write_uint64_hex(char* output, uint64_t v) { } } -pid_t UploadCrashDump(const char* filename, const char* crash_url, - unsigned crash_url_length) { +pid_t UploadCrashDump(const char* filename, + const char* crash_url, + unsigned crash_url_length, + const char* guid, + unsigned guid_length) { // WARNING: this code runs in a compromised context. It may not call into // libc nor allocate memory normally. @@ -128,6 +131,9 @@ pid_t UploadCrashDump(const char* filename, const char* crash_url, // Content-Disposition: form-data; name="ver" \r\n \r\n (11..15) // 1.2.3.4 \r\n (16, 17) // BOUNDARY \r\n (18, 19) + // Content-Disposition: form-data; name="guid" \r\n \r\n (20..24) + // 1.2.3.4 \r\n (25, 26) + // BOUNDARY \r\n (27, 28) // // zero or more: // Content-Disposition: form-data; name="url-chunk-1" \r\n \r\n (0..5) @@ -145,13 +151,14 @@ pid_t UploadCrashDump(const char* filename, const char* crash_url, static const char quote_msg[] = {'"'}; static const char chrome_linux_msg[] = "Chrome_Linux"; static const char ver_msg[] = "ver"; + static const char guid_msg[] = "guid"; static const char dashdash_msg[] = {'-', '-'}; static const char dump_msg[] = "upload_file_minidump\"; filename=\"dump\""; static const char content_type_msg[] = "Content-Type: application/octet-stream"; static const char url_chunk_msg[] = "url-chunk-"; - struct kernel_iovec iov[20]; + struct kernel_iovec iov[29]; iov[0].iov_base = mime_boundary; iov[0].iov_len = sizeof(mime_boundary) - 1; iov[1].iov_base = const_cast(rn); @@ -199,7 +206,28 @@ pid_t UploadCrashDump(const char* filename, const char* crash_url, iov[19].iov_base = const_cast(rn); iov[19].iov_len = sizeof(rn); - sys_writev(fd, iov, 20); + iov[20].iov_base = const_cast(form_data_msg); + iov[20].iov_len = sizeof(form_data_msg) - 1; + iov[21].iov_base = const_cast(guid_msg); + iov[21].iov_len = sizeof(guid_msg) - 1; + iov[22].iov_base = const_cast(quote_msg); + iov[22].iov_len = sizeof(quote_msg); + iov[23].iov_base = const_cast(rn); + iov[23].iov_len = sizeof(rn); + iov[24].iov_base = const_cast(rn); + iov[24].iov_len = sizeof(rn); + + iov[25].iov_base = const_cast(guid); + iov[25].iov_len = guid_length; + iov[26].iov_base = const_cast(rn); + iov[26].iov_len = sizeof(rn); + + iov[27].iov_base = mime_boundary; + iov[27].iov_len = sizeof(mime_boundary) - 1; + iov[28].iov_base = const_cast(rn); + iov[28].iov_len = sizeof(rn); + + sys_writev(fd, iov, 29); if (crash_url_length) { unsigned i = 0, done = 0; @@ -338,7 +366,7 @@ pid_t UploadCrashDump(const char* filename, const char* crash_url, id_buf[len] = 0; static const char msg[] = "\nCrash dump id: "; sys_write(2, msg, sizeof(msg) - 1); - sys_write(2, id_buf, my_strlen(buf)); + sys_write(2, id_buf, my_strlen(id_buf)); sys_write(2, "\n", 1); } sys_unlink(filename); @@ -369,6 +397,13 @@ pid_t UploadCrashDump(const char* filename, const char* crash_url, return child; } +// This is defined in chrome/browser/google_update_settings_linux.cc, it's the +// static string containing the user's unique GUID. We send this in the crash +// report. +namespace google_update { +extern std::string linux_guid; +} + static bool CrashDone(const char* dump_path, const char* minidump_id, void* context, @@ -390,7 +425,8 @@ static bool CrashDone(const char* dump_path, memcpy(path + dump_path_len + 1 + minidump_id_len, ".dmp", 4); path[dump_path_len + 1 + minidump_id_len + 4] = 0; - UploadCrashDump(path, NULL, 0); + UploadCrashDump(path, NULL, 0, google_update::linux_guid.data(), + google_update::linux_guid.length()); return true; } @@ -425,14 +461,16 @@ RendererCrashHandler(const void* crash_context, size_t crash_context_size, struct msghdr sys_msg; }; my_memset(&msg, 0, sizeof(struct kernel_msghdr)); - struct kernel_iovec iov[2]; + struct kernel_iovec iov[3]; iov[0].iov_base = const_cast(crash_context); iov[0].iov_len = crash_context_size; - iov[1].iov_base = const_cast(renderer_logging::active_url.data()); - iov[1].iov_len = renderer_logging::active_url.size(); + iov[1].iov_base = const_cast(google_update::linux_guid.data()); + iov[1].iov_len = google_update::linux_guid.size(); + iov[2].iov_base = const_cast(renderer_logging::active_url.data()); + iov[2].iov_len = renderer_logging::active_url.size(); msg.msg_iov = iov; - msg.msg_iovlen = 2; + msg.msg_iovlen = 3; char cmsg[kControlMsgSize]; memset(cmsg, 0, kControlMsgSize); msg.msg_control = cmsg; diff --git a/chrome/app/breakpad_linux.h b/chrome/app/breakpad_linux.h index 4df9b5e..e55d12e 100644 --- a/chrome/app/breakpad_linux.h +++ b/chrome/app/breakpad_linux.h @@ -6,7 +6,10 @@ #define CHROME_APP_BREAKPAD_LINUX_H_ extern void InitCrashReporter(); -extern int UploadCrashDump(const char* filename, const char* crash_url, - unsigned crash_url_length); +extern int UploadCrashDump(const char* filename, + const char* crash_url, + unsigned crash_url_length, + const char* guid, + unsigned guid_length); #endif // CHROME_APP_BREAKPAD_LINUX_H_ diff --git a/chrome/browser/google_update_settings_linux.cc b/chrome/browser/google_update_settings_linux.cc index f7ae4b5..d05ef09 100644 --- a/chrome/browser/google_update_settings_linux.cc +++ b/chrome/browser/google_update_settings_linux.cc @@ -7,17 +7,27 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/rand_util.h" +#include "base/string_util.h" #include "chrome/common/chrome_paths.h" +namespace google_update { +std::string linux_guid; +} + // File name used in the user data dir to indicate consent. static const char kConsentToSendStats[] = "Consent To Send Stats"; +static const int kGuidLen = sizeof(uint64) * 4; // 128 bits -> 32 bytes hex. // static bool GoogleUpdateSettings::GetCollectStatsConsent() { FilePath consent_file; PathService::Get(chrome::DIR_USER_DATA, &consent_file); consent_file = consent_file.Append(kConsentToSendStats); - return file_util::PathExists(consent_file); + bool r = file_util::ReadFileToString(consent_file, + &google_update::linux_guid); + google_update::linux_guid.resize(kGuidLen, '0'); + return r; } // static @@ -28,10 +38,21 @@ bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { return false; FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats); - if (consented) - return file_util::WriteFile(consent_file, "", 0) == 0; - else + if (consented) { + uint64 random; + google_update::linux_guid.clear(); + for (int i = 0; i < 2; i++) { + random = base::RandUint64(); + google_update::linux_guid += HexEncode(&random, sizeof(uint64)); + } + const char* c_str = google_update::linux_guid.c_str(); + return file_util::WriteFile(consent_file, c_str, kGuidLen) == kGuidLen; + } + else { + google_update::linux_guid .clear(); + google_update::linux_guid.resize(kGuidLen, '0'); return file_util::Delete(consent_file, false); + } } // static diff --git a/chrome/browser/renderer_host/render_crash_handler_host_linux.cc b/chrome/browser/renderer_host/render_crash_handler_host_linux.cc index a7342c5..87abf25 100644 --- a/chrome/browser/renderer_host/render_crash_handler_host_linux.cc +++ b/chrome/browser/renderer_host/render_crash_handler_host_linux.cc @@ -82,10 +82,11 @@ void RenderCrashHandlerHostLinux::OnFileCanReadWithoutBlocking(int fd) { static const unsigned kCrashContextSize = sizeof(google_breakpad::ExceptionHandler::CrashContext); static const unsigned kMaxActiveURLSize = 1024; + static const unsigned kGuidSize = 32; // 128 bits = 32 chars in hex. struct msghdr msg = {0}; struct iovec iov; - char context[kCrashContextSize + kMaxActiveURLSize]; + char context[kCrashContextSize + kMaxActiveURLSize + kGuidSize]; char control[kControlMsgSize]; iov.iov_base = context; iov.iov_len = sizeof(context); @@ -116,10 +117,12 @@ void RenderCrashHandlerHostLinux::OnFileCanReadWithoutBlocking(int fd) { return; } - // Anything in the message contents after the crash context is the crashing - // URL. - const char* const crash_url = &context[kCrashContextSize]; - const unsigned crash_url_len = n - kCrashContextSize; + // After the message contents we have the guid. + const char* const guid = &context[kCrashContextSize]; + + // Anything in the guid after the crash context is the crashing URL. + const char* const crash_url = &context[kCrashContextSize + kGuidSize]; + const unsigned crash_url_len = n - kCrashContextSize - kGuidSize; // Walk the control payload an extract the file descriptor and validated pid. pid_t crashing_pid = -1; @@ -179,7 +182,9 @@ void RenderCrashHandlerHostLinux::OnFileCanReadWithoutBlocking(int fd) { HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); HANDLE_EINTR(close(signal_fd)); - UploadCrashDump(minidump_filename.c_str(), crash_url, crash_url_len); + UploadCrashDump(minidump_filename.c_str(), + crash_url, crash_url_len, + guid, kGuidSize); } void RenderCrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { -- cgit v1.1