swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 63d8812d7789bd89d426c57ffb62a2ba95a0abaf
parent 09649f59786babe723eb870e8f0bb43743b142ac
Author: Michael Forney <mforney@mforney.org>
Date:   Sun, 16 Jun 2019 23:53:47 -0700

Use fixed size buffer for keymap path

Diffstat:
Mlibswc/keyboard.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libswc/keyboard.c b/libswc/keyboard.c @@ -34,6 +34,7 @@ #include <assert.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <string.h> #include <sys/mman.h> @@ -41,7 +42,6 @@ #include <xkbcommon/xkbcommon.h> static const int repeat_delay = 500, repeat_rate = 40; -static const char keymap_file_template[] = "swc-xkb-keymap-XXXXXX"; static void enter(struct input_focus_handler *handler, struct wl_list *resources, struct compositor_view *view) @@ -112,14 +112,14 @@ client_handle_modifiers(struct keyboard *keyboard, const struct keyboard_modifie static bool update_keymap(struct xkb *xkb) { + char keymap_path[PATH_MAX]; const char *keymap_directory; char *keymap_string; + int ret; if (!(keymap_directory = getenv("XDG_RUNTIME_DIR"))) keymap_directory = "/tmp"; - char keymap_path[strlen(keymap_directory) + 1 + sizeof(keymap_file_template)]; - xkb->indices.ctrl = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_CTRL); xkb->indices.alt = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_ALT); xkb->indices.super = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_LOGO); @@ -134,7 +134,11 @@ update_keymap(struct xkb *xkb) goto error0; } - sprintf(keymap_path, "%s/%s", keymap_directory, keymap_file_template); + ret = snprintf(keymap_path, sizeof(keymap_path), "%s/swc-xkb-keymap-XXXXXX", keymap_directory); + if (ret < 0 || (size_t)ret >= sizeof(keymap_path)) { + WARNING("Could not determine XKB keymap path\n"); + goto error1; + } xkb->keymap.size = strlen(keymap_string) + 1; xkb->keymap.fd = mkostemp(keymap_path, O_CLOEXEC);