mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-31 22:25:21 -04:00
Send unique keymap file descriptors
To prevent wl_keyboard keymap being written to by clients, use a unique file descriptor for each wl_keyboard resource. Reference: weston, commit 76829fc4eaea329d2a525c3978271e13bd76c078
This commit is contained in:
parent
8b112730ca
commit
40a43003a1
3 changed files with 33 additions and 34 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_data_device.h>
|
||||
#include <wlr/types/wlr_input_device.h>
|
||||
|
|
@ -10,6 +12,7 @@
|
|||
#include <wlr/util/log.h>
|
||||
#include "types/wlr_seat.h"
|
||||
#include "util/signal.h"
|
||||
#include "util/os-compatibility.h"
|
||||
|
||||
static void default_keyboard_enter(struct wlr_seat_keyboard_grab *grab,
|
||||
struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes,
|
||||
|
|
@ -338,9 +341,28 @@ static void seat_client_send_keymap(struct wlr_seat_client *client,
|
|||
continue;
|
||||
}
|
||||
|
||||
int keymap_fd = os_create_anonymous_file(keyboard->keymap_size);
|
||||
if (keymap_fd < 0) {
|
||||
wlr_log(WLR_ERROR, "creating a keymap file for %zu bytes failed", keyboard->keymap_size);
|
||||
continue;
|
||||
}
|
||||
|
||||
void *ptr = mmap(NULL, keyboard->keymap_size, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, keymap_fd, 0);
|
||||
if (ptr == MAP_FAILED) {
|
||||
wlr_log(WLR_ERROR, "failed to mmap() %zu bytes", keyboard->keymap_size);
|
||||
close(keymap_fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
strcpy(ptr, keyboard->keymap_string);
|
||||
munmap(ptr, keyboard->keymap_size);
|
||||
|
||||
wl_keyboard_send_keymap(resource,
|
||||
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd,
|
||||
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd,
|
||||
keyboard->keymap_size);
|
||||
|
||||
close(keymap_fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue