mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 04:36:07 +00:00
ipc: Read only the exact size of the ipc_command in client_loop on Linux
This commit is contained in:
parent
9b6eeb0bba
commit
81246de70a
|
@ -134,8 +134,6 @@ client_loop(volatile struct ipc_client_state *ics)
|
|||
return;
|
||||
}
|
||||
|
||||
uint8_t buf[IPC_BUF_SIZE] = {0};
|
||||
|
||||
while (ics->server->running) {
|
||||
const int half_a_second_ms = 500;
|
||||
struct epoll_event event = XRT_STRUCT_INIT;
|
||||
|
@ -163,10 +161,25 @@ client_loop(volatile struct ipc_client_state *ics)
|
|||
break;
|
||||
}
|
||||
|
||||
// Finally get the data that is waiting for us.
|
||||
//! @todo replace this call
|
||||
ssize_t len = recv(ics->imc.ipc_handle, &buf, IPC_BUF_SIZE, 0);
|
||||
if (len < 4) {
|
||||
// Peek the first 4 bytes to get the command type
|
||||
enum ipc_command cmd;
|
||||
ssize_t len = recv(ics->imc.ipc_handle, &cmd, sizeof(cmd), MSG_PEEK);
|
||||
if (len != sizeof(cmd)) {
|
||||
IPC_ERROR(ics->server, "Invalid command received.");
|
||||
break;
|
||||
}
|
||||
|
||||
size_t cmd_size = ipc_command_size(cmd);
|
||||
if (cmd_size == 0) {
|
||||
IPC_ERROR(ics->server, "Invalid command size.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Read the whole command now that we know its size
|
||||
uint8_t buf[IPC_BUF_SIZE] = {0};
|
||||
|
||||
len = recv(ics->imc.ipc_handle, &buf, cmd_size, 0);
|
||||
if (len != (ssize_t)cmd_size) {
|
||||
IPC_ERROR(ics->server, "Invalid packet received, disconnecting client.");
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue