Open jbeich opened 4 years ago
Same still happens with libxkbcommon-0.10.0, wayland-1.18.0, wlroots & wayfire both master as of right now
So wayvnc was doing ftruncate(0)
instead of ftruncate(size)
on the file descriptor, and it worked on Linux because shm_open
returns a regular file there: https://github.com/any1/wayvnc/pull/31
In our case, we were getting a fresh shm fd with nothing written to it, so basically uninitialized memory.
Maaaybe wlroots should validate that the incoming file is actually a string, i.e. that there's at least one zero byte in the size
bytes from the mmap
ped address.
Ideally libxkbcommon would take a length
parameter to xkb_keymap_new_from_string
:)
Ah, indeed. We can use xkb_keymap_new_from_buffer
instead. And checking for a final \0
is a good idea.
hm, the size
wayvnc uses does not include the final \0
, it just allocates strlen(keymap_string)
bytes. Which seems like a bug (for comparison, types/wlr_keyboard.c
does strlen() + 1
.. // upd: https://github.com/any1/wayvnc/pull/32) but that means if we add a hard check now, existing versions of wayvnc would be broken.
// virtual-keyboard-unstable-v1.xml
actually doesn't specify anything about that, neither does wayland.xml
, that's kinda sad
The Wayland protocol says it's the keymap size in bytes. The keymap isn't defined as a string, it's just an opaque buffer from the protocol point-of-view. So it does include the final NULL byte.
The Wayland protocol says it's the keymap size in bytes. The keymap isn't defined as a string, it's just an opaque buffer from the protocol point-of-view. So it does include the final NULL byte.
Isn't it possible to have the keymap stored in a textfile and just open that and send its filedescriptor to wlroots? In that case there wouldn't be a final NULL, right?
Isn't it possible to have the keymap stored in a textfile and just open that and send its filedescriptor to wlroots? In that case there wouldn't be a final NULL, right?
That's not possible, because the file could contain references to other files. Keymaps sent via Wayland need to be self-contained.
You can have a custom keymap in a self-contained file. In my opinion the delimiting NULL is an implementation detail that doesn't belong to the keymap itself, but to C strings. Since the protocol doesn't make any mention of that and it does provide the size in bytes, just use that and not bother with the NULL.
And in the unlikely future, libxkbcommon might even support keymaps in the compiled xkm format. (In my case that would reduce the size wayland has to shuffle around by more than half from 64 KB (with whitespace) or 40KB (without whitespace) to 13KB, but I guess that ship has sailed since clients already expect the textual representation)
You can have a custom keymap in a self-contained file.
There are more issues, e.g. clients could write to the file. Making FDs read-only require platform-specific mechanisms and a recent enough wl_seat
version for all clients.
In my opinion the delimiting NULL is an implementation detail that doesn't belong to the keymap itself, but to C strings. Since the protocol doesn't make any mention of that and it does provide the size in bytes, just use that and not bother with the NULL.
The protocol doesn't care about the final NULL byte, yes. However the libxkbcommon format does care. As soon as WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1
is used a final NULL byte is expected.
And in the unlikely future, libxkbcommon might even support keymaps in the compiled xkm format. (In my case that would reduce the size wayland has to shuffle around by more than half from 64 KB (with whitespace) or 40KB (without whitespace) to 13KB, but I guess that ship has sailed since clients already expect the textual representation)
Since shared memory is used, it's not that of a big deal.
Environment:
Steps to reproduce:
wlroots has migrated to gitlab.freedesktop.org. This issue has been moved to:
https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/2014