diff --git a/client/crash_report_database_generic.cc b/client/crash_report_database_generic.cc index fc1d04e0..e10c24fd 100644 --- a/client/crash_report_database_generic.cc +++ b/client/crash_report_database_generic.cc @@ -30,22 +30,6 @@ namespace crashpad { namespace { -// Reads from the current file position to EOF and returns as a string of bytes. -bool ReadRestOfFileAsString(FileHandle handle, std::string* contents) { - char buffer[4096]; - FileOperationResult rv; - std::string local_contents; - while ((rv = ReadFile(handle, buffer, sizeof(buffer))) > 0) { - local_contents.append(buffer, rv); - } - if (rv < 0) { - PLOG(ERROR) << "ReadFile"; - return false; - } - contents->swap(local_contents); - return true; -} - base::FilePath ReplaceFinalExtension( const base::FilePath& path, const base::FilePath::StringType extension) { @@ -768,7 +752,7 @@ bool CrashReportDatabaseGeneric::ReadMetadata(const base::FilePath& path, return false; } - if (!ReadRestOfFileAsString(handle.get(), &report->id)) { + if (!LoggingReadToEOF(handle.get(), &report->id)) { return false; } diff --git a/util/file/file_io.cc b/util/file/file_io.cc index f8a66304..55a6c5f1 100644 --- a/util/file/file_io.cc +++ b/util/file/file_io.cc @@ -156,16 +156,11 @@ void CheckedReadFileAtEOF(FileHandle file) { } } -bool LoggingReadEntireFile(const base::FilePath& path, std::string* contents) { - ScopedFileHandle handle(LoggingOpenFileForRead(path)); - if (!handle.is_valid()) { - return false; - } - +bool LoggingReadToEOF(FileHandle file, std::string* contents) { char buffer[4096]; FileOperationResult rv; std::string local_contents; - while ((rv = ReadFile(handle.get(), buffer, sizeof(buffer))) > 0) { + while ((rv = ReadFile(file, buffer, sizeof(buffer))) > 0) { DCHECK_LE(static_cast(rv), sizeof(buffer)); local_contents.append(buffer, rv); } @@ -177,6 +172,15 @@ bool LoggingReadEntireFile(const base::FilePath& path, std::string* contents) { return true; } +bool LoggingReadEntireFile(const base::FilePath& path, std::string* contents) { + ScopedFileHandle handle(LoggingOpenFileForRead(path)); + if (!handle.is_valid()) { + return false; + } + + return LoggingReadToEOF(handle.get(), contents); +} + void CheckedCloseFile(FileHandle file) { CHECK(LoggingCloseFile(file)); } diff --git a/util/file/file_io.h b/util/file/file_io.h index 050c0749..797db682 100644 --- a/util/file/file_io.h +++ b/util/file/file_io.h @@ -318,7 +318,13 @@ void CheckedWriteFile(FileHandle file, const void* buffer, size_t size); //! \sa ReadFile void CheckedReadFileAtEOF(FileHandle file); -//! brief Wraps LoggingOpenFileForRead() and ReadFile() reading the entire file +//! \brief Wraps ReadFile() to read from the current file position to the end of +//! the file into \a contents. +//! +//! \return `true` on success, or `false` with a message logged. +bool LoggingReadToEOF(FileHandle file, std::string* contents); + +//! \brief Wraps LoggingOpenFileForRead() and ReadFile() reading the entire file //! into \a contents. //! //! \return `true` on success, or `false` with a message logged. diff --git a/util/net/http_transport_socket.cc b/util/net/http_transport_socket.cc index 6e2e7aaa..a6bce455 100644 --- a/util/net/http_transport_socket.cc +++ b/util/net/http_transport_socket.cc @@ -367,14 +367,9 @@ bool ReadResponse(int sock, std::string* response_body) { if (it != response_headers.end() && it->second == "chunked") { chunked = true; } - if (!chunked) { - // TODO(scottmg): https://crashpad.chromium.org/bug/196. Doesn't happen - // in practice, but is possible. - LOG(ERROR) << "unimplemented non-chunked without Content-Length"; - return false; - } - return ReadContentChunked(sock, response_body); + return chunked ? ReadContentChunked(sock, response_body) + : LoggingReadToEOF(sock, response_body); } bool HTTPTransportSocket::ExecuteSynchronously(std::string* response_body) {