0

[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/+/2461225
Reviewed-by: Erik 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}
This commit is contained in:
Lambros Lambrou
2020-10-14 01:53:25 +00:00
committed by Commit Bot
parent 4ad8ec7572
commit 0585160de9

@ -66,6 +66,24 @@ class RtcLogFileReader : public FileOperations::Reader {
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)
: connection_(connection) {}
RtcLogFileReader::~RtcLogFileReader() = default;
@ -175,6 +193,28 @@ int RtcLogFileReader::ReadPartially(int maximum_to_read,
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
RtcLogFileOperations::RtcLogFileOperations(
@ -188,8 +228,7 @@ std::unique_ptr<FileOperations::Reader> RtcLogFileOperations::CreateReader() {
}
std::unique_ptr<FileOperations::Writer> RtcLogFileOperations::CreateWriter() {
NOTREACHED() << "RTC event log is read-only.";
return nullptr;
return std::make_unique<RtcLogFileWriter>();
}
} // namespace remoting