Skip to content

Commit

Permalink
Merge branch 'master' into meta/bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Dec 3, 2021
2 parents a545377 + fe19de6 commit 620f0cc
Show file tree
Hide file tree
Showing 394 changed files with 6,980 additions and 2,777 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*.xcodeproj
*~
.*.sw?
.cache
.DS_Store
.gdb_history
.gdbinit
Expand Down
5 changes: 5 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) {
fuchsia_test_package("crashpad-test") {
test_components = [ ":crashpad-test-component" ]

deps = [
"//src/connectivity/network/dns:component-legacy",
"//src/connectivity/network/netstack:component-legacy",
]

test_specs = {
log_settings = {
max_severity = "FATAL"
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ deps = {
'7bde79cc274d06451bf65ae82c012a5d3e476b5a',
'crashpad/third_party/mini_chromium/mini_chromium':
Var('chromium_git') + '/chromium/mini_chromium@' +
'8f7a60f2c637f2a3c5d25f320739b3de7c2e325d',
'0e22eed71eec97dacbe80822a14c5cd0b580d793',
'crashpad/third_party/libfuzzer/src':
Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' +
'fda403cf93ecb8792cb1d061564d89a6553ca020',
Expand Down
8 changes: 3 additions & 5 deletions build/crashpad_buildconfig.gni
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ crashpad_is_standalone = crashpad_dependencies == "standalone"

# This is the parent directory that contains the mini_chromium source dir.
# This variable is not used when crashpad_is_in_chromium.
if (crashpad_is_external || crashpad_is_in_dart) {
# External and Dart SDK builds assume crashpad and mini_chromium are peers.
mini_chromium_source_parent = "../mini_chromium"
} else if (crashpad_is_in_fuchsia) {
if (crashpad_is_in_fuchsia) {
mini_chromium_source_parent = "//third_party/crashpad/third_party/mini_chromium"
} else {
mini_chromium_source_parent = "../third_party/mini_chromium"
Expand All @@ -50,7 +47,7 @@ _mini_chromium_source_root = "$mini_chromium_source_parent/mini_chromium"

# This references the mini_chromium location for importing GN files.
if (crashpad_is_external || crashpad_is_in_dart) {
mini_chromium_import_root = "../../$_mini_chromium_source_root"
mini_chromium_import_root = "../../../$_mini_chromium_source_root"
} else if (crashpad_is_in_fuchsia) {
mini_chromium_import_root = "//third_party/mini_chromium"
} else {
Expand All @@ -70,6 +67,7 @@ if (crashpad_is_in_chromium) {
crashpad_is_clang = is_clang
} else {
import("$mini_chromium_import_root/build/compiler.gni")
import("$mini_chromium_import_root/build/platform.gni")

crashpad_is_mac = mini_chromium_is_mac
crashpad_is_ios = mini_chromium_is_ios
Expand Down
6 changes: 5 additions & 1 deletion client/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ crashpad_static_library("client") {
"crashpad_client_ios.cc",
"ios_handler/exception_processor.h",
"ios_handler/exception_processor.mm",
"ios_handler/in_process_handler.cc",
"ios_handler/in_process_handler.h",
"ios_handler/in_process_intermediate_dump_handler.cc",
"ios_handler/in_process_intermediate_dump_handler.h",
"ios_handler/prune_intermediate_dumps_and_crash_reports_thread.cc",
"ios_handler/prune_intermediate_dumps_and_crash_reports_thread.h",
"simulate_crash_ios.h",
]
}
Expand Down Expand Up @@ -84,7 +88,6 @@ crashpad_static_library("client") {
cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union
}

# TODO(justincohen): Temporary dependency to bring up the iOS client.
if (crashpad_is_ios) {
deps += [
"../handler:common",
Expand Down Expand Up @@ -167,6 +170,7 @@ source_set("client_test") {
sources += [
"crashpad_client_ios_test.mm",
"ios_handler/exception_processor_test.mm",
"ios_handler/in_process_handler_test.cc",
"ios_handler/in_process_intermediate_dump_handler_test.cc",
]
}
Expand Down
11 changes: 6 additions & 5 deletions client/annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <sys/types.h>

#include "base/check.h"
#include "base/macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -139,6 +138,9 @@ class Annotation {
size_(0),
type_(type) {}

Annotation(const Annotation&) = delete;
Annotation& operator=(const Annotation&) = delete;

//! \brief Specifies the number of bytes in \a value_ptr_ to include when
//! generating a crash report.
//!
Expand Down Expand Up @@ -189,8 +191,6 @@ class Annotation {
void* const value_ptr_;
ValueSizeType size_;
const Type type_;

DISALLOW_COPY_AND_ASSIGN(Annotation);
};

//! \brief An \sa Annotation that stores a `NUL`-terminated C-string value.
Expand All @@ -214,6 +214,9 @@ class StringAnnotation : public Annotation {
constexpr explicit StringAnnotation(const char name[])
: Annotation(Type::kString, name, value_), value_() {}

StringAnnotation(const StringAnnotation&) = delete;
StringAnnotation& operator=(const StringAnnotation&) = delete;

//! \brief Constructs a new StringAnnotation with the given \a name.
//!
//! This constructor takes the ArrayInitializerTag for use when
Expand Down Expand Up @@ -262,8 +265,6 @@ class StringAnnotation : public Annotation {
// This value is not `NUL`-terminated, since the size is stored by the base
// annotation.
char value_[MaxSize];

DISALLOW_COPY_AND_ASSIGN(StringAnnotation);
};

} // namespace crashpad
Expand Down
7 changes: 4 additions & 3 deletions client/annotation_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef CRASHPAD_CLIENT_ANNOTATION_LIST_H_
#define CRASHPAD_CLIENT_ANNOTATION_LIST_H_

#include "base/macros.h"
#include "build/build_config.h"
#include "client/annotation.h"

Expand All @@ -35,6 +34,10 @@ class InProcessIntermediateDumpHandler;
class AnnotationList {
public:
AnnotationList();

AnnotationList(const AnnotationList&) = delete;
AnnotationList& operator=(const AnnotationList&) = delete;

~AnnotationList();

//! \brief Returns the instance of the list that has been registered on the
Expand Down Expand Up @@ -102,8 +105,6 @@ class AnnotationList {
// Dummy linked-list head and tail elements of \a Annotation::Type::kInvalid.
Annotation head_;
Annotation tail_;

DISALLOW_COPY_AND_ASSIGN(AnnotationList);
};

} // namespace crashpad
Expand Down
109 changes: 109 additions & 0 deletions client/crash_report_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@

#include "client/crash_report_database.h"

#include <sys/stat.h>

#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "util/file/directory_reader.h"
#include "util/file/filesystem.h"

namespace crashpad {

namespace {
constexpr base::FilePath::CharType kAttachmentsDirectory[] =
FILE_PATH_LITERAL("attachments");

bool AttachmentNameIsOK(const std::string& name) {
for (const char c : name) {
if (c != '_' && c != '-' && c != '.' && !isalnum(c))
return false;
}
return true;
}
} // namespace

CrashReportDatabase::Report::Report()
: uuid(),
file_path(),
Expand Down Expand Up @@ -73,6 +92,60 @@ FileReaderInterface* CrashReportDatabase::NewReport::Reader() {
return reader_.get();
}

FileWriter* CrashReportDatabase::NewReport::AddAttachment(
const std::string& name) {
if (!AttachmentNameIsOK(name)) {
LOG(ERROR) << "invalid name for attachment " << name;
return nullptr;
}
base::FilePath report_attachments_dir = database_->AttachmentsPath(uuid_);
if (!LoggingCreateDirectory(
report_attachments_dir, FilePermissions::kOwnerOnly, true)) {
return nullptr;
}
#if defined(OS_WIN)
const std::wstring name_string = base::UTF8ToWide(name);
#else
const std::string name_string = name;
#endif
base::FilePath attachment_path = report_attachments_dir.Append(name_string);
auto writer = std::make_unique<FileWriter>();
if (!writer->Open(attachment_path,
FileWriteMode::kCreateOrFail,
FilePermissions::kOwnerOnly)) {
return nullptr;
}
attachment_writers_.emplace_back(std::move(writer));
attachment_removers_.emplace_back(ScopedRemoveFile(attachment_path));
return attachment_writers_.back().get();
}

void CrashReportDatabase::UploadReport::InitializeAttachments() {
base::FilePath report_attachments_dir = database_->AttachmentsPath(uuid);
DirectoryReader dir_reader;
if (!dir_reader.Open(report_attachments_dir)) {
return;
}

base::FilePath filename;
DirectoryReader::Result dir_result;
while ((dir_result = dir_reader.NextFile(&filename)) ==
DirectoryReader::Result::kSuccess) {
const base::FilePath filepath(report_attachments_dir.Append(filename));
std::unique_ptr<FileReader> file_reader(std::make_unique<FileReader>());
if (!file_reader->Open(filepath)) {
continue;
}
attachment_readers_.emplace_back(std::move(file_reader));
#if defined(OS_WIN)
const std::string name_string = base::WideToUTF8(filename.value());
#else
const std::string name_string = filename.value();
#endif
attachment_map_[name_string] = attachment_readers_.back().get();
}
}

CrashReportDatabase::UploadReport::UploadReport()
: Report(),
reader_(std::make_unique<FileReader>()),
Expand Down Expand Up @@ -103,4 +176,40 @@ CrashReportDatabase::OperationStatus CrashReportDatabase::RecordUploadComplete(
return RecordUploadAttempt(report, true, id);
}

base::FilePath CrashReportDatabase::AttachmentsPath(const UUID& uuid) {
#if defined(OS_WIN)
const std::wstring uuid_string = uuid.ToWString();
#else
const std::string uuid_string = uuid.ToString();
#endif

return DatabasePath().Append(kAttachmentsDirectory).Append(uuid_string);
}

base::FilePath CrashReportDatabase::AttachmentsRootPath() {
return DatabasePath().Append(kAttachmentsDirectory);
}

void CrashReportDatabase::RemoveAttachmentsByUUID(const UUID& uuid) {
base::FilePath report_attachment_dir = AttachmentsPath(uuid);
if (!IsDirectory(report_attachment_dir, /*allow_symlinks=*/false)) {
return;
}
DirectoryReader reader;
if (!reader.Open(report_attachment_dir)) {
return;
}

base::FilePath filename;
DirectoryReader::Result result;
while ((result = reader.NextFile(&filename)) ==
DirectoryReader::Result::kSuccess) {
const base::FilePath attachment_path(
report_attachment_dir.Append(filename));
LoggingRemoveFile(attachment_path);
}

LoggingRemoveDirectory(report_attachment_dir);
}

} // namespace crashpad
Loading

0 comments on commit 620f0cc

Please sign in to comment.