Skip to content

Commit

Permalink
Fix attachments name instead of ignoring with error (#67)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Syluanov <[email protected]>
  • Loading branch information
saf-e and saf-e authored Jun 1, 2022
1 parent df2cb4c commit 21d03ee
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions client/crash_report_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ 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;
std::string FixAttachmentName(std::string name) {
std::replace_if(name.begin(), name.end(), [&](char c)
{
return c != '_' && c != '-' && c != '.' && !isalnum(c);
}, '_');

return name;
}
} // namespace

Expand Down Expand Up @@ -94,19 +95,15 @@ FileReaderInterface* CrashReportDatabase::NewReport::Reader() {

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 BUILDFLAG(IS_WIN)
const std::wstring name_string = base::UTF8ToWide(name);
const std::wstring name_string = base::UTF8ToWide(FixAttachmentName(name));
#else
const std::string name_string = name;
const std::string name_string = FixAttachmentName(name);
#endif
base::FilePath attachment_path = report_attachments_dir.Append(name_string);
auto writer = std::make_unique<FileWriter>();
Expand Down

0 comments on commit 21d03ee

Please sign in to comment.