Commit graph

1230 commits

Author SHA1 Message Date
Peter Hutterer
bca07c3dc0 brei: fix missing bounds checks in protocol demarshalling
The brei_demarshal() function parses incoming protocol messages based on
a type signature. While the 's' (string) type had proper bounds checking
against the remaining buffer, the other types didn't.

A malicious client could send a message with a truncated payload (small
msglen in the header) but targeting an opcode whose signature expects
more data than provided. This would cause buffer over-reads past the
allocated buffer, potentially leaking sensitive memory contents or
causing a crash.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/389>
2026-05-13 11:15:41 +10:00
Peter Hutterer
fc5129968d brei: put a warning in that disabling NDEBUG is not a good idea
We really rely on assert all over the place, removing that is likely
going to result in interesting outcomes when unexpected failures happen.

Putting this into brei because it's a header used by both libei/libeis.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:26 +00:00
Peter Hutterer
93ba922062 brei: fail on under/oversized message lengths
Add a 1MiB maximum and make sure our message length
is at least the header size - without that we get an underflow, causing
iobuf_pop to remove a huge number of bytes, crashing the other end.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:26 +00:00
Peter Hutterer
581806d28e tools: verify the libxkbcommon utf8 symbols
This is mostly to shut up analyzers that aren't happy with the strcat
usage here.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:26 +00:00
Peter Hutterer
4ec936f016 tools: use xatou in the demo client/server
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:26 +00:00
Peter Hutterer
dc5bd1396f eis: handle a lock file open failure correctly
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
c352f16b4a eis: restrict our socket to owner-only
Depending on the umask our socket may be group/world-accessible, let's
not do that because if the current state of the world tells us anything
it is that we can't trust it.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
2b9b001db9 eis: our socket lockfile doesn't need group permissions
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
c436bd37ec eis: fix two file descriptor leaks on error
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
62ac026432 oeffis: handle fcntl failures correctly
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
7d42a95d12 util: replace strcat memcpy in strv_join
Repeatedly using strcat means we rescan the string, making it O(n^2).
Use memcpy and an offset instead because we can't affort to waste
nanoseconds here.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
80e2b4e4d9 util: close excessive file descriptors in iobuf_recv_from_fd
Unceremoneously close any fds that the client gives us that exceed our
expectations (which right now is a max of 32 for a protocol-valid max
of... 1).

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
f63b44d8ae util: allow for a maximum of 32 fds in xsend_with_fds
Our current maximum of fds per the protocol is exactly 1 so this has
no effect but might save us in the future from some naughty client.
Meanwhile, this prevents us from having a variable-length array on the
stack that is caller-controller.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
1b4a0d7c1a util: handle failing memfd sealing
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
f12fe4ce14 util: fix possible fd leak if xconnect fails on connect()
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
1efc6d03d1 util: only close fds larger than -1 in cleanup_close
This allows us to pass xerrno() results (i.e. negative errnos) and still
do the right thing.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:25 +00:00
Peter Hutterer
c6c8f47b43 util: add a steal_fd() helper function
We can't use steal for fds because of the -1 requirement.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:24 +00:00
Peter Hutterer
4440f15453 util: return NULL in memmap_new() for a size 0
Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:24 +00:00
Peter Hutterer
bacd62cae0 util: fix xatou_base for values > UINT_MAX
The check `(long)v < 0` only catches values >= LONG_MAX when cast to
signed long. On 64-bit systems where sizeof(long) == 8, values between
UINT_MAX+1 and LONG_MAX pass this check but silently truncate when
assigned to the unsigned int output parameter. Use `v > UINT_MAX` for
a correct range check.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:24 +00:00
Peter Hutterer
bbcc808b1a util: use x{re}alloc, not the libc ones
Might as well blow up when allocation fails, not that this ever happens.

And in the case of cmdline_as_str() this now also means we definitely
have to free the result (we did before but well, there was the
theoretical case of it failling).

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:24 +00:00
Peter Hutterer
e2197b8389 util: xrealloc should take a size_t
For correctness only because this is C and types are mostly
just there for lolz, not because they're actualy useful.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
2026-05-13 01:02:24 +00:00
Peter Hutterer
61600a6577 CI: run clang-format to make sure the coding style is correct
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/390>
2026-05-13 10:05:50 +10:00
Peter Hutterer
fefbdd7b01 tools: run clang-format
Fixes: cd7ec93eda ("Let oeffis-demo-tool start ei-demo-client optionally")
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/390>
2026-05-13 10:05:50 +10:00
David Redondo
cd7ec93eda Let oeffis-demo-tool start ei-demo-client optionally 2026-05-12 08:43:04 +02:00
Peter Hutterer
cea415fc40 eis: send missing ei_text interface version
The protocol test we had was broken, it would assume that any interface
we send was present instead of only taking the ones the server replied
with. Fix this so this triggers next time.

Fixes: 1f9be0fd0a ("Add a new text interface for sending keysyms and utf8 text")
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/387>
2026-04-24 15:33:35 +10:00
Peter Hutterer
428984ce75 ei: fix formatting for the VERSION_UPDATE calls
clang-format did quite a mess of this, let's disable formatting for this

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/387>
2026-04-24 15:07:38 +10:00
Peter Hutterer
2c85e2bd9c Revert "Add support for swipe, pinch and hold gestures"
This reverts commit ff9e8905a0.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/386>
2026-04-23 14:19:29 +10:00
Peter Hutterer
ff9e8905a0 Add support for swipe, pinch and hold gestures
On the protocol level these are implemented as three separate interfaces
for swipe, pinch and hold, each interface has the begin/update/end
sequence and effectively matches the wayland pointer-gestures protocol.

Notably, only one of each gesture may be active at any time though the
protocol allows for separate gestures to be active (i.e. swipe while
pinching).

On the library side the gestures match the touch interface so the
sequence for a sender is:

  swipe = ei_device_new_swipe(device, finger_count);
  ei_swipe_begin(swipe);
  ei_swipe_update(swipe, dx, dy);
  ei_swipe_end(swipe);

with the corresponding APIs for pinch and hold.

On the receiver side the event types are separated for BEGIN/UPDATE/END
for all three gestures and thus match the libinput interface.

The notable difference however: there is only one CAP_GESTURES (similar
to libinput) and it is set if any gesture is available on the caller.
Creating a swipe gesture if the remote end does not support it will
return NULL though.

Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/309>
2026-04-21 11:12:29 +10:00
Peter Hutterer
1f9be0fd0a Add a new text interface for sending keysyms and utf8 text
The text capability allows for two types of events on that interface:
- XKB keysym events, e.g. XK_ssharp (0x00df) with a press/release state
- UTF8 strings

Keysym events are useful for scenarious where the hardware keycode is
unsuitable due to potentially different key mappings on the client and
server side and/or the client just not wanting to worry about those
mappings. For example a client may want to send Ctrl+C instead of
what effectively is now keycodes for what may or may not be a C key.

UTF8 strings take this a step further and provide a full string (with
implementation-defined size limits to avoid OOM). Unlike e.g. the
wayland text input protocols the assumption is here that the
interaction required to generate that string has already been
performed before the final string is sent over the wire.

Closes #73

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/355>
2026-04-02 05:09:37 +00:00
Peter Hutterer
c5494e9b1e Fix varius typos across the codebase
Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/385>
2026-03-23 12:37:45 +10:00
Peter Hutterer
b96ec4ad08 test: fix three copy/paste bugs in the logcapture
Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/385>
2026-03-23 12:37:45 +10:00
Peter Hutterer
abac405f2a Add .git-blame-ignore-revs to ignore the clang-format commit
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/384>
2026-03-12 13:59:32 +10:00
Peter Hutterer
a6028a7b87 Format the code with clang-format
clang-format taken from libinput, except for
  ColumnLimit: 100
and some macro definitions (which don't all have an effect anyway...)

It's not perfect but good enough and at least consistent.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/383>
2026-03-12 13:55:19 +10:00
Peter Hutterer
98cd152b70 eis: store the sequence number in start_emulating
Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/381>
2026-03-12 03:47:23 +00:00
Peter Hutterer
b4f45f2aff Add missing return after scroll capability checks
For both ei/eis a missing return after the scroll capability check could
cause a potential NULL pointer dereference on device->scroll.

Co-Authored-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/382>
2026-03-12 03:35:20 +00:00
Peter Hutterer
d0b5180a88 oeffis: avoid array overflow for sender_name
Found by: Claude Code <noreply@anthropic.com>

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/380>
2026-03-12 03:31:19 +00:00
Peter Hutterer
e5c72682da util: fix heap buffer overflow in xread_with_fds()
This situation cannot happen in a normal protocol conversation, the only
message that transports an fd (ei_keyboard.keymap) has one single fd and
(32 + 1 * sizeof(int)) is large enough on the platforms that matters.

fd transport is always EIS to ei, so a long as EIS is trusted enough,
this is not a security issue that matters.

Found-by: Claude Code <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/380>
2026-03-12 03:31:19 +00:00
Peter Hutterer
5141212fb4 If the connection fails on ei(s)_ping, disconnect
Like any other request if we fail to write the ping event on the wire
assume we or the client are dead and emulate a disconnection.

Closes: #92
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/379>
2026-03-06 16:26:29 +10:00
Peter Hutterer
25df541fb1 eis: fix a comment typo
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/379>
2026-03-06 16:26:29 +10:00
Peter Hutterer
32abd87cc7 util: ifndef the etrace and trace macros
This macros are incredibly useful to use globally so let's ifdef them
out in case developers have them sitting around in global headers.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/378>
2026-03-06 13:51:02 +10:00
Peter Hutterer
aa5571ec08 CI: drop the ci-fairy check-mr job
The only thing this checked was the checkbox for allowing maintainers to
edit the MR. Changed permissions checks now fail this job but luckily
the setting it checked has been the default for years anyway so we can
drop it.

https://gitlab.freedesktop.org/freedesktop/ci-templates/-/issues/81

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/376>
2026-02-17 06:18:06 +00:00
Ian Douglas Scott
9883a2ba2a ei: Don't send request_name with NULL name
Sending `NULL` here is a protocol violation since this is not marked as
`allow-null` in the protocol spec.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/375>
2026-02-16 19:15:43 -08:00
Peter Hutterer
e8994dfe17 util: add handling for an auto type
Because sometimes it's much easier and more readable, e.g.
 auto eis_device = eis_touchscreen_get_device(...)

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/373>
2026-01-07 22:24:43 +00:00
Peter Hutterer
180c9f2890 proto: add a blurb about events to send during stop_emulating
This should've been specified from day one but better late than never.
Since stop_emulating is supposed to signal termination of a client
emulating input, a logical assumption is that the device is set back to
neutral. Let's point it out that the real behavior is within EIS but
clients should behave predictably.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/368>
2026-01-07 22:23:42 +00:00
Peter Hutterer
57064f6846 eis: end any ongoing touch in response to touch_end
Even if the client is no longer emulating (and we're not queuing an
event) our local touch must be ended. Otherwise our touch will live on
forever, despite the client thinking it has ended properly.

This can't be triggered with libei because we can't send touch events
while not emulating and the only way to get into this state is pausing
the device - which already resets the state. But let's add a test case
anyway, in the hope that one day it picks up a bug.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/368>
2026-01-07 22:23:42 +00:00
Peter Hutterer
330b54d389 eis: keep track of touch IDs and don't allow duplicate ones
A client sending duplicate touch IDs will be disconnected but
motion or end events for touches that no longer exist will be silently
ignored.

The tracking state uses a uint64_t to store currently valid touch ids -
since the whole range of touch ids are uint32_t (including zero) this is
the simple way of using an out-of-range marker value (UINT64_MAX)

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/368>
2026-01-07 22:23:42 +00:00
Peter Hutterer
84c23989e9 eis: quietly ignore double key presses and releases
This is only implemented on the EIS side of things because that side is
mostly what we want to protect (read: the compositors). The duplicates
are still sent on the protocol.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/368>
2026-01-07 22:23:42 +00:00
Peter Hutterer
65c0b39c3e ei: match the EI_EVENT_DEVICE_PAUSED docs with the protocol
This is a behavior break if we're looking at the documentation only but
the protocol has required the logical reset of the device since libei
0.5 - this here is just stale documentation that didn't get updated.

And keeping the state across paused/resume is too hard to get right
anyway.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/368>
2026-01-07 22:23:41 +00:00
Peter Hutterer
9446918556 CI: update to Fedora 43
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/374>
2026-01-06 04:52:47 +00:00
Peter Hutterer
5f9e181073 proto: add support for requesting devices
Add support for a client to request the creation of a new device
from the EIS implementation. This is necessary in situations where the
devices created by the EIS implementation are not (or no longer)
suitable for the client to function correctly.

The primary use-case of this is the upcoming tablet tool support where a
client may need to create multiple tablet tools in response to a new
physical tool brought into proximity locally.

Other use-cases include a client closing a device but requiring that
device (or one with similar capabilities) later.

The implementation in libei is straightforward
- on the client side we have a new function to request the new device:
  ei_seat_request_device_with_capabilities()
- on the server side we have a new event EIS_EVENT_SEAT_DEVICE_REQUESTED
  that can make use of the existing eis_event_seat_has_capability() API

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/345>
2026-01-06 04:50:46 +00:00