aboutsummaryrefslogtreecommitdiffstats
path: root/epan/register.c
diff options
context:
space:
mode:
Diffstat (limited to 'epan/register.c')
-rw-r--r--epan/register.c70
1 files changed, 57 insertions, 13 deletions
diff --git a/epan/register.c b/epan/register.c
index e8387c112a..1f8f2c2fa5 100644
--- a/epan/register.c
+++ b/epan/register.c
@@ -12,11 +12,15 @@
#include "ws_attributes.h"
#include <glib.h>
+
+#include <epan/exceptions.h>
+
#include "epan/dissectors/dissectors.h"
static const char *cur_cb_name = NULL;
-// We could use g_atomic_pointer_set/get instead of a mutex, but that's
-// currently (early 2018) invisible to TSAN.
+// We could use g_atomic_pointer_set/get instead of a mutex, but that causes
+// a false positive with Clang and TSAN for GLib < 2.64.0 (Issue #17753):
+// https://gitlab.gnome.org/GNOME/glib/-/issues/1843
static GMutex cur_cb_name_mtx;
static GAsyncQueue *register_cb_done_q;
@@ -31,13 +35,30 @@ static void set_cb_name(const char *proto) {
static void *
register_all_protocols_worker(void *arg _U_)
{
- for (gulong i = 0; i < dissector_reg_proto_count; i++) {
- set_cb_name(dissector_reg_proto[i].cb_name);
- dissector_reg_proto[i].cb_func();
+ void *volatile error_message = NULL;
+
+ TRY {
+ for (gulong i = 0; i < dissector_reg_proto_count; i++) {
+ set_cb_name(dissector_reg_proto[i].cb_name);
+ dissector_reg_proto[i].cb_func();
+ }
}
+ CATCH(DissectorError) {
+ /*
+ * This is probably a dissector, or something it calls,
+ * calling REPORT_DISSECTOR_ERROR() in a registration
+ * routine or something else outside the normal dissection
+ * code path.
+ *
+ * The message gets freed by ENDTRY, so we must make a copy
+ * of it.
+ */
+ error_message = g_strdup(GET_MESSAGE);
+ }
+ ENDTRY;
g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
- return NULL;
+ return (void *) error_message;
}
void
@@ -47,6 +68,7 @@ register_all_protocols(register_cb cb, gpointer cb_data)
register_cb_done_q = g_async_queue_new();
gboolean called_back = FALSE;
GThread *rapw_thread;
+ const char *error_message;
rapw_thread = g_thread_new("register_all_protocols_worker", &register_all_protocols_worker, NULL);
while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) {
@@ -58,7 +80,9 @@ register_all_protocols(register_cb cb, gpointer cb_data)
called_back = TRUE;
}
}
- g_thread_join(rapw_thread);
+ error_message = (const char *) g_thread_join(rapw_thread);
+ if (error_message != NULL)
+ THROW_MESSAGE(DissectorError, error_message);
if (cb && !called_back) {
cb(RA_REGISTER, "finished", cb_data);
}
@@ -67,23 +91,41 @@ register_all_protocols(register_cb cb, gpointer cb_data)
static void *
register_all_protocol_handoffs_worker(void *arg _U_)
{
- for (gulong i = 0; i < dissector_reg_handoff_count; i++) {
- set_cb_name(dissector_reg_handoff[i].cb_name);
- dissector_reg_handoff[i].cb_func();
+ void *volatile error_message = NULL;
+
+ TRY {
+ for (gulong i = 0; i < dissector_reg_handoff_count; i++) {
+ set_cb_name(dissector_reg_handoff[i].cb_name);
+ dissector_reg_handoff[i].cb_func();
+ }
+ }
+ CATCH(DissectorError) {
+ /*
+ * This is probably a dissector, or something it calls,
+ * calling REPORT_DISSECTOR_ERROR() in a registration
+ * routine or something else outside the normal dissection
+ * code path.
+ *
+ * The message gets freed by ENDTRY, so we must make a copy
+ * of it.
+ */
+ error_message = g_strdup(GET_MESSAGE);
}
+ ENDTRY;
g_async_queue_push(register_cb_done_q, GINT_TO_POINTER(TRUE));
- return NULL;
+ return (void *) error_message;
}
void
register_all_protocol_handoffs(register_cb cb, gpointer cb_data)
{
- cur_cb_name = NULL;
const char *cb_name;
gboolean called_back = FALSE;
GThread *raphw_thread;
+ const char *error_message;
+ set_cb_name(NULL);
raphw_thread = g_thread_new("register_all_protocol_handoffs_worker", &register_all_protocol_handoffs_worker, NULL);
while (!g_async_queue_timeout_pop(register_cb_done_q, CB_WAIT_TIME)) {
g_mutex_lock(&cur_cb_name_mtx);
@@ -94,7 +136,9 @@ register_all_protocol_handoffs(register_cb cb, gpointer cb_data)
called_back = TRUE;
}
}
- g_thread_join(raphw_thread);
+ error_message = (const char *) g_thread_join(raphw_thread);
+ if (error_message != NULL)
+ THROW_MESSAGE(DissectorError, error_message);
if (cb && !called_back) {
cb(RA_HANDOFF, "finished", cb_data);
}