Commit 5618e036 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Add a mutex to detect recursive use of feedkeys (fixes #5)

parent c888c93b
...@@ -296,6 +296,8 @@ struct girara_session_private_s ...@@ -296,6 +296,8 @@ struct girara_session_private_s
girara_list_t* shortcut_mappings; girara_list_t* shortcut_mappings;
girara_list_t* argument_mappings; girara_list_t* argument_mappings;
} config; } config;
GMutex feedkeys_mutex;
}; };
#endif #endif
...@@ -314,6 +314,7 @@ girara_session_create(void) ...@@ -314,6 +314,7 @@ girara_session_create(void)
session_private->elements.statusbar_items = girara_list_new2( session_private->elements.statusbar_items = girara_list_new2(
(girara_free_function_t) girara_statusbar_item_free); (girara_free_function_t) girara_statusbar_item_free);
g_mutex_init(&session_private->feedkeys_mutex);
/* settings */ /* settings */
session_private->settings = girara_sorted_list_new2( session_private->settings = girara_sorted_list_new2(
...@@ -612,6 +613,9 @@ girara_session_private_free(girara_session_private_t* session) ...@@ -612,6 +613,9 @@ girara_session_private_free(girara_session_private_t* session)
girara_list_free(session->settings); girara_list_free(session->settings);
session->settings = NULL; session->settings = NULL;
/* clean up mutex */
g_mutex_clear(&session->feedkeys_mutex);
g_slice_free(girara_session_private_t, session); g_slice_free(girara_session_private_t, session);
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "datastructures.h" #include "datastructures.h"
#include "input-history.h" #include "input-history.h"
#include "internal.h" #include "internal.h"
#include "log.h"
#include "session.h" #include "session.h"
#include "settings.h" #include "settings.h"
...@@ -523,6 +524,11 @@ girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument, ...@@ -523,6 +524,11 @@ girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument,
return false; return false;
} }
if (g_mutex_trylock(&session->private_data->feedkeys_mutex) == FALSE) {
girara_error("Recursive use of feedkeys detected. Aborting evaluation.");
return false;
}
typedef struct gdk_keyboard_button_s { typedef struct gdk_keyboard_button_s {
char* identifier; char* identifier;
int keyval; int keyval;
...@@ -575,7 +581,7 @@ girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument, ...@@ -575,7 +581,7 @@ girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument,
goto single_key; goto single_key;
} }
int length = end - (input + i) - 1; const int length = end - (input + i) - 1;
char* tmp = g_strndup(input + i + 1, length); char* tmp = g_strndup(input + i + 1, length);
bool found = false; bool found = false;
...@@ -633,6 +639,7 @@ single_key: ...@@ -633,6 +639,7 @@ single_key:
} }
} }
g_mutex_unlock(&session->private_data->feedkeys_mutex);
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment