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
girara_list_t* shortcut_mappings;
girara_list_t* argument_mappings;
} config;
GMutex feedkeys_mutex;
};
#endif
......@@ -314,6 +314,7 @@ girara_session_create(void)
session_private->elements.statusbar_items = girara_list_new2(
(girara_free_function_t) girara_statusbar_item_free);
g_mutex_init(&session_private->feedkeys_mutex);
/* settings */
session_private->settings = girara_sorted_list_new2(
......@@ -612,6 +613,9 @@ girara_session_private_free(girara_session_private_t* session)
girara_list_free(session->settings);
session->settings = NULL;
/* clean up mutex */
g_mutex_clear(&session->feedkeys_mutex);
g_slice_free(girara_session_private_t, session);
}
......
......@@ -5,6 +5,7 @@
#include "datastructures.h"
#include "input-history.h"
#include "internal.h"
#include "log.h"
#include "session.h"
#include "settings.h"
......@@ -523,6 +524,11 @@ girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument,
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 {
char* identifier;
int keyval;
......@@ -575,7 +581,7 @@ girara_sc_feedkeys(girara_session_t* session, girara_argument_t* argument,
goto single_key;
}
int length = end - (input + i) - 1;
const int length = end - (input + i) - 1;
char* tmp = g_strndup(input + i + 1, length);
bool found = false;
......@@ -633,6 +639,7 @@ single_key:
}
}
g_mutex_unlock(&session->private_data->feedkeys_mutex);
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