Commit 0585160d authored by Lambros Lambrou's avatar Lambros Lambrou Committed by Commit Bot

[remoting host] Don't crash if website attempts RTC file upload.

This replaces a NOTREACHED() with a basic RTC log writer implementation
that simply returns a protocol error to the client. The RTC log
FileOperations class is meant to be download-only, but the file-transfer
protocol permits the client to try to upload files to it. This code-path
is never intended to be exercised - this CL simply prevents the host
from crashing in this situation.

Bug: 1122798
Change-Id: I838e575530a89b837f64f2fe28c29fd291a88820
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461225Reviewed-by: default avatarErik Jensen <rkjnsn@chromium.org>
Commit-Queue: Erik Jensen <rkjnsn@chromium.org>
Auto-Submit: Lambros Lambrou <lambroslambrou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816843}
parent 4ad8ec75
...@@ -66,6 +66,24 @@ class RtcLogFileReader : public FileOperations::Reader { ...@@ -66,6 +66,24 @@ class RtcLogFileReader : public FileOperations::Reader {
base::WeakPtrFactory<RtcLogFileReader> weak_factory_{this}; base::WeakPtrFactory<RtcLogFileReader> weak_factory_{this};
}; };
// This class simply returns a protocol error if the client attempts to upload
// a file to this FileOperations implementation. The RTC log is download-only,
// and the upload code-path is never intended to be executed. This class is
// intended to gracefully return an error instead of crashing the host process.
class RtcLogFileWriter : public FileOperations::Writer {
public:
RtcLogFileWriter() = default;
~RtcLogFileWriter() override = default;
RtcLogFileWriter(const RtcLogFileWriter&) = delete;
RtcLogFileWriter& operator=(const RtcLogFileWriter&) = delete;
// FileOperations::Writer interface.
void Open(const base::FilePath& filename, Callback callback) override;
void WriteChunk(std::vector<std::uint8_t> data, Callback callback) override;
void Close(Callback callback) override;
FileOperations::State state() const override;
};
RtcLogFileReader::RtcLogFileReader(protocol::ConnectionToClient* connection) RtcLogFileReader::RtcLogFileReader(protocol::ConnectionToClient* connection)
: connection_(connection) {} : connection_(connection) {}
RtcLogFileReader::~RtcLogFileReader() = default; RtcLogFileReader::~RtcLogFileReader() = default;
...@@ -175,6 +193,28 @@ int RtcLogFileReader::ReadPartially(int maximum_to_read, ...@@ -175,6 +193,28 @@ int RtcLogFileReader::ReadPartially(int maximum_to_read,
return read_amount; return read_amount;
} }
void RtcLogFileWriter::Open(const base::FilePath& filename, Callback callback) {
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(
std::move(callback),
protocol::MakeFileTransferError(
FROM_HERE, protocol::FileTransfer_Error_Type_PROTOCOL_ERROR)));
}
void RtcLogFileWriter::WriteChunk(std::vector<std::uint8_t> data,
Callback callback) {
NOTREACHED();
}
void RtcLogFileWriter::Close(Callback callback) {
NOTREACHED();
}
FileOperations::State RtcLogFileWriter::state() const {
return FileOperations::State::kFailed;
}
} // namespace } // namespace
RtcLogFileOperations::RtcLogFileOperations( RtcLogFileOperations::RtcLogFileOperations(
...@@ -188,8 +228,7 @@ std::unique_ptr<FileOperations::Reader> RtcLogFileOperations::CreateReader() { ...@@ -188,8 +228,7 @@ std::unique_ptr<FileOperations::Reader> RtcLogFileOperations::CreateReader() {
} }
std::unique_ptr<FileOperations::Writer> RtcLogFileOperations::CreateWriter() { std::unique_ptr<FileOperations::Writer> RtcLogFileOperations::CreateWriter() {
NOTREACHED() << "RTC event log is read-only."; return std::make_unique<RtcLogFileWriter>();
return nullptr;
} }
} // namespace remoting } // namespace remoting
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment