Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions client/crash_report_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,29 @@ bool CrashReportDatabase::Envelope::Initialize(const base::FilePath& path) {

CrashReportDatabase::Envelope::Envelope(const UUID& uuid) : uuid_(uuid) {}

// static
bool CrashReportDatabase::Envelope::IsEvent(const base::FilePath& attachment) {
const base::FilePath::StringType basename = attachment.BaseName().value();
return basename == FILE_PATH_LITERAL("__sentry-event");
}

// static
bool CrashReportDatabase::Envelope::IsBreadcrumb(
const base::FilePath& attachment) {
const base::FilePath::StringType basename = attachment.BaseName().value();
return basename.rfind(FILE_PATH_LITERAL("__sentry-breadcrumb"), 0) == 0;
}

void CrashReportDatabase::Envelope::AddAttachments(
const std::vector<base::FilePath>& attachments) {
base::FilePath event;
std::vector<base::FilePath> breadcrumbs;
std::vector<base::FilePath> others;

for (const auto& attachment : attachments) {
#if BUILDFLAG(IS_WIN)
std::string basename = base::WideToUTF8(attachment.BaseName().value());
#else
std::string basename = attachment.BaseName().value();
#endif
if (basename == "__sentry-event") {
if (IsEvent(attachment)) {
event = attachment;
} else if (basename.rfind("__sentry-breadcrumb", 0) == 0) {
} else if (IsBreadcrumb(attachment)) {
breadcrumbs.push_back(attachment);
} else {
others.push_back(attachment);
Expand Down
6 changes: 6 additions & 0 deletions client/crash_report_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ class CrashReportDatabase {
//! \param[in] reader File reader for the minidump data.
void AddMinidump(FileReaderInterface* reader);

//! \brief Returns `true` if \a attachment is the event attachment.
static bool IsEvent(const base::FilePath& attachment);

//! \brief Returns `true` if \a attachment is a breadcrumb attachment.
static bool IsBreadcrumb(const base::FilePath& attachment);

//! \brief Finalizes the feedback report and closes file handles.
void Finish();

Expand Down
9 changes: 9 additions & 0 deletions client/crashpad_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <stdint.h>

#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "build/build_config.h"
#include "util/file/file_io.h"
Expand Down Expand Up @@ -865,6 +866,14 @@ class CrashpadClient {
//! \param[in] attachment The path to the file to be added.
void AddAttachment(const base::FilePath& attachment);

//! \brief Writes content to an attachment file.
bool WriteAttachment(
const base::FilePath& attachment, base::span<const uint8_t> data);

//! \brief Appends content to an attachment file.
bool AppendAttachment(
const base::FilePath& attachment, base::span<const uint8_t> data);

//! \brief Removes a file from the list of files to be attached to the crash
//! report.
//!
Expand Down
29 changes: 29 additions & 0 deletions client/crashpad_client_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/futex.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <sys/socket.h>
Expand All @@ -38,6 +39,7 @@
#include "third_party/lss/lss.h"
#include "util/file/file_io.h"
#include "util/file/filesystem.h"
#include "util/file/file_writer.h"
#include "util/linux/exception_handler_client.h"
#include "util/linux/exception_information.h"
#include "util/linux/scoped_pr_set_dumpable.h"
Expand Down Expand Up @@ -832,6 +834,33 @@ void CrashpadClient::AddAttachment(const base::FilePath& attachment) {
signal_handler->AddAttachment(attachment);
}

bool CrashpadClient::WriteAttachment(const base::FilePath& attachment,
base::span<const uint8_t> data) {
FileWriter writer;
if (!writer.Open(attachment,
FileWriteMode::kTruncateOrCreate,
FilePermissions::kOwnerOnly) ||
!writer.Write(data.data(), data.size())) {
LOG(ERROR) << "failed to write attachment " << attachment;
return false;
}
return true;
}

bool CrashpadClient::AppendAttachment(const base::FilePath& attachment,
base::span<const uint8_t> data) {
FileWriter writer;
if (!writer.Open(attachment,
FileWriteMode::kReuseOrCreate,
FilePermissions::kOwnerOnly) ||
writer.Seek(0, SEEK_END) < 0 ||
!writer.Write(data.data(), data.size())) {
LOG(ERROR) << "failed to write attachment " << attachment;
return false;
}
return true;
}

void CrashpadClient::RemoveAttachment(const base::FilePath& attachment) {
auto signal_handler = RequestCrashDumpHandler::Get();
signal_handler->RemoveAttachment(attachment);
Expand Down
29 changes: 29 additions & 0 deletions client/crashpad_client_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <mach/mach.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>

#include <memory>
Expand All @@ -29,6 +30,7 @@
#include "base/check_op.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "util/file/file_writer.h"
#include "util/mac/mac_util.h"
#include "util/mach/bootstrap.h"
#include "util/mach/child_port_handshake.h"
Expand Down Expand Up @@ -637,6 +639,33 @@ void CrashpadClient::AddAttachment(const base::FilePath& attachment) {
attachment.value());
}

bool CrashpadClient::WriteAttachment(const base::FilePath& attachment,
base::span<const uint8_t> data) {
FileWriter writer;
if (!writer.Open(attachment,
FileWriteMode::kTruncateOrCreate,
FilePermissions::kOwnerOnly) ||
!writer.Write(data.data(), data.size())) {
LOG(ERROR) << "failed to write attachment " << attachment;
return false;
}
return true;
}

bool CrashpadClient::AppendAttachment(const base::FilePath& attachment,
base::span<const uint8_t> data) {
FileWriter writer;
if (!writer.Open(attachment,
FileWriteMode::kReuseOrCreate,
FilePermissions::kOwnerOnly) ||
writer.Seek(0, SEEK_END) < 0 ||
!writer.Write(data.data(), data.size())) {
LOG(ERROR) << "failed to write attachment " << attachment;
return false;
}
return true;
}

void CrashpadClient::RemoveAttachment(const base::FilePath& attachment) {
SendClientToServerMessage(exception_port_.get(),
ClientToServerMessage::kRemoveAttachment,
Expand Down
104 changes: 96 additions & 8 deletions client/crashpad_client_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1216,19 +1216,107 @@ void CrashpadClient::SetFirstChanceExceptionHandler(
}

void CrashpadClient::AddAttachment(const base::FilePath& attachment) {
const size_t path_length_bytes =
(attachment.value().length() + 1) * sizeof(wchar_t);
if (path_length_bytes > kMaxPathBytes) {
LOG(ERROR) << "Path too long: " << path_length_bytes << " bytes";
return;
}

ClientToServerMessage message = {};
message.type = ClientToServerMessage::kAddAttachmentV2;
message.attachment_v2.path_length_bytes =
static_cast<uint32_t>(path_length_bytes);

ServerToClientMessage response = {};
SendPayloadToCrashHandlerServer(ipc_pipe_,
message,
base::as_bytes(base::make_span(
attachment.value().c_str(),
path_length_bytes / sizeof(wchar_t))),
{},
&response);
}

bool CrashpadClient::WriteAttachment(const base::FilePath& attachment,
base::span<const uint8_t> data) {
const size_t path_length_bytes =
(attachment.value().length() + 1) * sizeof(wchar_t);
if (path_length_bytes > kMaxPathBytes ||
data.size() > kMaxAttachmentPayloadBytes ||
data.size() > UINT32_MAX - path_length_bytes) {
LOG(ERROR) << "attachment content too large";
return false;
}

ClientToServerMessage message = {};
message.type = ClientToServerMessage::kWriteAttachment;
message.attachment_write.path_length_bytes =
static_cast<uint32_t>(path_length_bytes);
message.attachment_write.payload_length_bytes =
static_cast<uint32_t>(data.size());

ServerToClientMessage response = {};
SendAttachmentToCrashHandlerServer(ipc_pipe_,
ClientToServerMessage::kAddAttachmentV2,
attachment.value(),
&response);
return SendPayloadToCrashHandlerServer(ipc_pipe_,
message,
base::as_bytes(base::make_span(
attachment.value().c_str(),
path_length_bytes
/ sizeof(wchar_t))),
data,
&response);
Comment thread
jpnurmi marked this conversation as resolved.
}

bool CrashpadClient::AppendAttachment(const base::FilePath& attachment,
base::span<const uint8_t> data) {
const size_t path_length_bytes =
(attachment.value().length() + 1) * sizeof(wchar_t);
if (path_length_bytes > kMaxPathBytes ||
data.size() > kMaxAttachmentPayloadBytes ||
data.size() > UINT32_MAX - path_length_bytes) {
LOG(ERROR) << "attachment content too large";
return false;
}

ClientToServerMessage message = {};
message.type = ClientToServerMessage::kAppendAttachment;
message.attachment_write.path_length_bytes =
static_cast<uint32_t>(path_length_bytes);
message.attachment_write.payload_length_bytes =
Comment thread
jpnurmi marked this conversation as resolved.
static_cast<uint32_t>(data.size());

ServerToClientMessage response = {};
return SendPayloadToCrashHandlerServer(ipc_pipe_,
message,
base::as_bytes(base::make_span(
attachment.value().c_str(),
path_length_bytes
/ sizeof(wchar_t))),
data,
&response);
}

void CrashpadClient::RemoveAttachment(const base::FilePath& attachment) {
const size_t path_length_bytes =
(attachment.value().length() + 1) * sizeof(wchar_t);
if (path_length_bytes > kMaxPathBytes) {
LOG(ERROR) << "Path too long: " << path_length_bytes << " bytes";
return;
}

ClientToServerMessage message = {};
message.type = ClientToServerMessage::kRemoveAttachmentV2;
message.attachment_v2.path_length_bytes =
static_cast<uint32_t>(path_length_bytes);

ServerToClientMessage response = {};
SendAttachmentToCrashHandlerServer(ipc_pipe_,
ClientToServerMessage::kRemoveAttachmentV2,
attachment.value(),
&response);
SendPayloadToCrashHandlerServer(ipc_pipe_,
message,
base::as_bytes(base::make_span(
attachment.value().c_str(),
path_length_bytes / sizeof(wchar_t))),
{},
&response);
}

void CrashpadClient::RequestRetry() {
Expand Down
Loading
Loading