uint32_t modifiers)
{
WaylandIMContext *imcontext = (WaylandIMContext *)data;
- char string[32], key[32], keyname[32];
+ char string[32] = {'\0'};
+ char key[32] = {'\0'};
+ char keyname[32] = {'\0'};
Ecore_Event_Key *e;
memset(key, 0, sizeof(key));
SECURE_LOGD("key event (key: %s)", keyname);
- e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
- strlen(string) + 3);
+ unsigned int key_len = strlen(key);
+ unsigned int key_name_len = strlen(keyname);
+ unsigned int key_string_len = strlen(string);
+
+ if (key_len > sizeof(key)-1)
+ key_len = sizeof(key)-1;
+
+ if (key_name_len > sizeof(keyname)-1)
+ key_name_len = sizeof(keyname)-1;
+
+ if (key_string_len > sizeof(string)-1)
+ key_string_len = sizeof(string)-1;
+
+ e = calloc(1, sizeof(Ecore_Event_Key) + key_len + key_name_len +
+ key_string_len + 3);
if (!e) return;
e->keyname = (char *)(e + 1);
- e->key = e->keyname + strlen(keyname) + 1;
- e->string = e->key + strlen(key) + 1;
+ e->key = e->keyname + key_name_len + 1;
+ e->string = e->key + key_len + 1;
e->compose = e->string;
- strncpy((char *)e->keyname, keyname, strlen(keyname));
- strncpy((char *)e->key, key, strlen(key));
- strncpy((char *)e->string, string, strlen(string));
+ memcpy((void *)e->keyname, keyname, key_name_len);
+ *((char *)e->keyname + key_name_len + 1) = '\0';
+ memcpy((void *)e->key, key, key_len);
+ *((char *)e->key + key_len + 1) = '\0';
+ memcpy((void *)e->string, string, key_string_len);
+ *((char *)e->string + key_string_len + 1) = '\0';
e->window = (Ecore_Window)ecore_wl2_window_id_get(imcontext->window);
e->event_window = (Ecore_Window)ecore_wl2_window_id_get(imcontext->window);