Check if attachment directories exist before open

TESTED=`fx run-test crashpad_test -- --gtest_filter=Filesystem.Is*`

Change-Id: If5940e56fbfd890e73d4403b530bc3e4a32e0365
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1796965
Commit-Queue: Francois Rousseau <frousseau@google.com>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Alex Pankhurst 2019-09-10 13:40:27 -07:00 committed by Commit Bot
parent 2bfd3c4edc
commit 12bc30cdf5

View File

@ -173,8 +173,7 @@ off_t GetFileSize(const base::FilePath& filepath) {
void AddAttachmentSize(const base::FilePath& attachments_dir, uint64_t* size) { void AddAttachmentSize(const base::FilePath& attachments_dir, uint64_t* size) {
// Early return if the attachment directory does not exist. // Early return if the attachment directory does not exist.
struct stat statbuf; if (!IsDirectory(attachments_dir, /*allow_symlinks=*/false)) {
if (stat(attachments_dir.value().c_str(), &statbuf) != 0) {
return; return;
} }
DirectoryReader reader; DirectoryReader reader;
@ -334,6 +333,9 @@ void CrashReportDatabase::UploadReport::InitializeAttachments() {
base::FilePath attachments_dir = base::FilePath attachments_dir =
static_cast<CrashReportDatabaseGeneric*>(database_)->AttachmentsPath( static_cast<CrashReportDatabaseGeneric*>(database_)->AttachmentsPath(
uuid); uuid);
if (!IsDirectory(attachments_dir, /*allow_symlinks=*/false)) {
return;
}
DirectoryReader reader; DirectoryReader reader;
if (!reader.Open(attachments_dir)) { if (!reader.Open(attachments_dir)) {
return; return;
@ -873,7 +875,6 @@ void CrashReportDatabaseGeneric::CleanOrphanedAttachments() {
base::FilePath root_attachments_dir(base_dir_.Append(kAttachmentsDirectory)); base::FilePath root_attachments_dir(base_dir_.Append(kAttachmentsDirectory));
DirectoryReader reader; DirectoryReader reader;
if (!reader.Open(root_attachments_dir)) { if (!reader.Open(root_attachments_dir)) {
LOG(ERROR) << "no attachments dir";
return; return;
} }
@ -914,6 +915,9 @@ void CrashReportDatabaseGeneric::CleanOrphanedAttachments() {
void CrashReportDatabaseGeneric::RemoveAttachmentsByUUID(const UUID& uuid) { void CrashReportDatabaseGeneric::RemoveAttachmentsByUUID(const UUID& uuid) {
base::FilePath attachments_dir = AttachmentsPath(uuid); base::FilePath attachments_dir = AttachmentsPath(uuid);
if (!IsDirectory(attachments_dir, /*allow_symlinks=*/false)) {
return;
}
DirectoryReader reader; DirectoryReader reader;
if (!reader.Open(attachments_dir)) { if (!reader.Open(attachments_dir)) {
return; return;