mirror of
https://github.com/swaywm/sway.git
synced 2026-04-21 06:46:22 -04:00
The server loops endlessly in following scenarios:
- client sends less bytes than IPC header requires
- client sends less bytes than defined by payload size
- client sends more payload data than buffered by operating system
This happens because the server relies on the buffering in sockets by
the operating system. The server only retrieves bytes from buffer when
enough bytes are available. To prevent this, store data in heap.
Also check supplied payload length before working with that value.
Proof of Concept client in Python (you will notice that sway process
consumes a lot of CPU while the client is running):
```
import os
import socket
swaysock=os.environ['SWAYSOCK']
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(swaysock)
client.send(b'\x69\x33\x2D\x69\x70\x63\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00')
input('Press enter to quit.')
```
44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
#ifndef _SWAY_IPC_H
|
|
#define _SWAY_IPC_H
|
|
|
|
#define event_mask(ev) (1 << (ev & 0x7F))
|
|
|
|
// maximum size of payload is 4 MB
|
|
#define IPC_MAX_SIZE 4e6
|
|
|
|
enum ipc_command_type {
|
|
// i3 command types - see i3's I3_REPLY_TYPE constants
|
|
IPC_COMMAND = 0,
|
|
IPC_GET_WORKSPACES = 1,
|
|
IPC_SUBSCRIBE = 2,
|
|
IPC_GET_OUTPUTS = 3,
|
|
IPC_GET_TREE = 4,
|
|
IPC_GET_MARKS = 5,
|
|
IPC_GET_BAR_CONFIG = 6,
|
|
IPC_GET_VERSION = 7,
|
|
IPC_GET_BINDING_MODES = 8,
|
|
IPC_GET_CONFIG = 9,
|
|
IPC_SEND_TICK = 10,
|
|
IPC_SYNC = 11,
|
|
IPC_GET_BINDING_STATE = 12,
|
|
|
|
// sway-specific command types
|
|
IPC_GET_INPUTS = 100,
|
|
IPC_GET_SEATS = 101,
|
|
|
|
// Events sent from sway to clients. Events have the highest bits set.
|
|
IPC_EVENT_WORKSPACE = ((1<<31) | 0),
|
|
IPC_EVENT_OUTPUT = ((1<<31) | 1),
|
|
IPC_EVENT_MODE = ((1<<31) | 2),
|
|
IPC_EVENT_WINDOW = ((1<<31) | 3),
|
|
IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4),
|
|
IPC_EVENT_BINDING = ((1<<31) | 5),
|
|
IPC_EVENT_SHUTDOWN = ((1<<31) | 6),
|
|
IPC_EVENT_TICK = ((1<<31) | 7),
|
|
|
|
// sway-specific event types
|
|
IPC_EVENT_BAR_STATE_UPDATE = ((1<<31) | 20),
|
|
IPC_EVENT_INPUT = ((1<<31) | 21),
|
|
};
|
|
|
|
#endif
|