commit 63d8812

Michael Forney  ·  2019-06-17 06:53:47 +0000 UTC
parent 09649f5
Use fixed size buffer for keymap path
1 files changed,  +8, -4
+8, -4
 1@@ -34,6 +34,7 @@
 2 
 3 #include <assert.h>
 4 #include <fcntl.h>
 5+#include <limits.h>
 6 #include <stdio.h>
 7 #include <string.h>
 8 #include <sys/mman.h>
 9@@ -41,7 +42,6 @@
10 #include <xkbcommon/xkbcommon.h>
11 
12 static const int repeat_delay = 500, repeat_rate = 40;
13-static const char keymap_file_template[] = "swc-xkb-keymap-XXXXXX";
14 
15 static void
16 enter(struct input_focus_handler *handler, struct wl_list *resources, struct compositor_view *view)
17@@ -112,14 +112,14 @@ client_handle_modifiers(struct keyboard *keyboard, const struct keyboard_modifie
18 static bool
19 update_keymap(struct xkb *xkb)
20 {
21+	char keymap_path[PATH_MAX];
22 	const char *keymap_directory;
23 	char *keymap_string;
24+	int ret;
25 
26 	if (!(keymap_directory = getenv("XDG_RUNTIME_DIR")))
27 		keymap_directory = "/tmp";
28 
29-	char keymap_path[strlen(keymap_directory) + 1 + sizeof(keymap_file_template)];
30-
31 	xkb->indices.ctrl = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_CTRL);
32 	xkb->indices.alt = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_ALT);
33 	xkb->indices.super = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_LOGO);
34@@ -134,7 +134,11 @@ update_keymap(struct xkb *xkb)
35 		goto error0;
36 	}
37 
38-	sprintf(keymap_path, "%s/%s", keymap_directory, keymap_file_template);
39+	ret = snprintf(keymap_path, sizeof(keymap_path), "%s/swc-xkb-keymap-XXXXXX", keymap_directory);
40+	if (ret < 0 || (size_t)ret >= sizeof(keymap_path)) {
41+		WARNING("Could not determine XKB keymap path\n");
42+		goto error1;
43+	}
44 
45 	xkb->keymap.size = strlen(keymap_string) + 1;
46 	xkb->keymap.fd = mkostemp(keymap_path, O_CLOEXEC);