mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:17:35 +00:00
LibIPC: Ensure message sizes do not exceed the limits of u32
We encode the size as a u32, so let's be sure the size does not exceed that storage. This is unlikely to happen, but no reason not to check.
This commit is contained in:
parent
91558fa381
commit
f2db700ae7
1 changed files with 7 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/Checked.h>
|
||||||
#include <LibCore/Socket.h>
|
#include <LibCore/Socket.h>
|
||||||
#include <LibIPC/Message.h>
|
#include <LibIPC/Message.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
@ -14,7 +15,12 @@ using MessageSizeType = u32;
|
||||||
|
|
||||||
ErrorOr<void> MessageBuffer::transfer_message(Core::LocalSocket& fd_passing_socket, Core::LocalSocket& data_socket)
|
ErrorOr<void> MessageBuffer::transfer_message(Core::LocalSocket& fd_passing_socket, Core::LocalSocket& data_socket)
|
||||||
{
|
{
|
||||||
MessageSizeType message_size = data.size();
|
Checked<MessageSizeType> checked_message_size { data.size() };
|
||||||
|
|
||||||
|
if (checked_message_size.has_overflow())
|
||||||
|
return Error::from_string_literal("Message is too large for IPC encoding");
|
||||||
|
|
||||||
|
auto message_size = checked_message_size.value();
|
||||||
TRY(data.try_prepend(reinterpret_cast<u8 const*>(&message_size), sizeof(message_size)));
|
TRY(data.try_prepend(reinterpret_cast<u8 const*>(&message_size), sizeof(message_size)));
|
||||||
|
|
||||||
for (auto const& fd : fds)
|
for (auto const& fd : fds)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue