From d9d42bcfeb444652ae198a6bd3481ce316549e55 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sat, 29 Jun 2024 13:15:29 +0200 Subject: kernel: Use local error codes for kernel calls. So that we know which process caused the error, and it's not global as well. Signed-off-by: Amlal EL Mahrouss --- Kernel/Sources/Network/IPCEP.cxx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'Kernel/Sources/Network') diff --git a/Kernel/Sources/Network/IPCEP.cxx b/Kernel/Sources/Network/IPCEP.cxx index e3a40fb9..0cd9d778 100644 --- a/Kernel/Sources/Network/IPCEP.cxx +++ b/Kernel/Sources/Network/IPCEP.cxx @@ -5,3 +5,39 @@ ------------------------------------------- */ #include + +using namespace NewOS; + +Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) +{ + if (!pckt) return false; + + auto endian = DEDUCE_ENDIAN(pckt, ((char*)pckt)[0]); + + switch (endian) + { + case Endian::kEndianBig: + { + if (pckt->IpcEndianess == eIPCEPLittleEndian) + return false; + + break; + } + case Endian::kEndianLittle: + { + if (pckt->IpcEndianess == eIPCEPBigEndian) + return false; + + break; + } + case Endian::kEndianMixed: + break; + default: + return false; + } + + if (pckt->IpcFrom == pckt->IpcTo) return false; + if (pckt->IpcPacketSize > cIPCEPMsgSize) return false; + + return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; +} -- cgit v1.2.3