1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 17:47:45 +00:00

AK: Add trivial structure validation to SharedBuffer

If we're sharing buffers, we only want to share trivial structures
as anything else could potentially share internal pointers, which
most likely is going to cause problems due to different address
spaces.

Fix the GUI::SystemTheme structure, which was not trivial, which
is now caught at compile time.

Fixes #3650
This commit is contained in:
Tom 2020-09-30 20:00:59 -06:00 committed by Andreas Kling
parent 87f20f704c
commit 7399874479
16 changed files with 48 additions and 29 deletions

View file

@ -83,7 +83,7 @@ OwnPtr<Messages::ClipboardServer::GetClipboardDataResponse> ClientConnection::ha
// It would be even nicer if a SharedBuffer could have an arbitrary number of clients..
RefPtr<SharedBuffer> shared_buffer = SharedBuffer::create_with_size(storage.data_size());
ASSERT(shared_buffer);
memcpy(shared_buffer->data(), storage.data(), storage.data_size());
memcpy(shared_buffer->data<void>(), storage.data(), storage.data_size());
shared_buffer->seal();
shared_buffer->share_with(client_pid());
shbuf_id = shared_buffer->shbuf_id();

View file

@ -46,7 +46,7 @@ Storage::~Storage()
void Storage::set_data(NonnullRefPtr<SharedBuffer> data, size_t data_size, const String& mime_type, const HashMap<String, String>& metadata)
{
dbg() << "Storage::set_data <- [" << mime_type << "] " << data->data() << " (" << data_size << " bytes)";
dbg() << "Storage::set_data <- [" << mime_type << "] " << data->data<void>() << " (" << data_size << " bytes)";
for (auto& it : metadata) {
dbg() << " " << it.key << ": " << it.value;
}

View file

@ -47,7 +47,7 @@ public:
{
if (!has_data())
return nullptr;
return static_cast<const u8*>(m_shared_buffer->data());
return m_shared_buffer->data<u8>();
}
size_t data_size() const

View file

@ -79,7 +79,7 @@ OwnPtr<Messages::ImageDecoderServer::DecodeImageResponse> ClientConnection::hand
dbg() << "Trying to decode " << message.encoded_size() << " bytes of image(?) data in shbuf_id=" << message.encoded_shbuf_id() << " (shbuf size: " << encoded_buffer->size() << ")";
#endif
auto decoder = Gfx::ImageDecoder::create((const u8*)encoded_buffer->data(), message.encoded_size());
auto decoder = Gfx::ImageDecoder::create(encoded_buffer->data<u8>(), message.encoded_size());
auto bitmap = decoder->bitmap();
if (!bitmap) {

View file

@ -91,7 +91,7 @@ void ClientConnection::did_finish_download(Badge<Download>, Download& download,
RefPtr<SharedBuffer> buffer;
if (success && download.payload().size() > 0 && !download.payload().is_null()) {
buffer = SharedBuffer::create_with_size(download.payload().size());
memcpy(buffer->data(), download.payload().data(), download.payload().size());
memcpy(buffer->data<void>(), download.payload().data(), download.payload().size());
buffer->seal();
buffer->share_with(client_pid());
m_shared_buffers.set(buffer->shbuf_id(), buffer);

View file

@ -50,7 +50,7 @@ void PageHost::setup_palette()
{
// FIXME: Get the proper palette from our peer somehow
auto buffer = SharedBuffer::create_with_size(sizeof(Gfx::SystemTheme));
auto* theme = (Gfx::SystemTheme*)buffer->data();
auto* theme = buffer->data<Gfx::SystemTheme>();
theme->color[(int)Gfx::ColorRole::Window] = Color::Magenta;
theme->color[(int)Gfx::ColorRole::WindowText] = Color::Cyan;
m_palette_impl = Gfx::PaletteImpl::create_with_shared_buffer(*buffer);