Catch REPORT_DISSECTOR_BUG() calls in dissector registration routines.
authorGuy Harris <guy@alum.mit.edu>
Wed, 28 Oct 2015 00:41:23 +0000 (17:41 -0700)
committerGuy Harris <guy@alum.mit.edu>
Wed, 28 Oct 2015 00:44:26 +0000 (00:44 +0000)
Have epan_init() return a success/failure Boolean indication.  Catch
exceptions when calling the dissector registration routines and, if we
get one, report the error and return a failure indication.

If epan_init() fails, quit, but first make sure the reported error is
displayed.

Change-Id: I0300cbb1f66a5644f857a205235124909d684c50
Reviewed-on: https://code.wireshark.org/review/11340
Reviewed-by: Guy Harris <guy@alum.mit.edu>
dftest.c
epan/epan.c
epan/epan.h
rawshark.c
tfshark.c
tshark.c
ui/gtk/main.c
wireshark-qt.cpp

index c721afcdd0104fb905a50cae8e69ece4dfd07674..9af46c16a1249390d22e9bddfc78660cc2c61d7f 100644 (file)
--- a/dftest.c
+++ b/dftest.c
@@ -95,8 +95,9 @@ main(int argc, char **argv)
           "-g" flag, as the "-g" flag dumps a list of fields registered
           by the dissectors, and we must do it before we read the preferences,
           in case any dissectors register preferences. */
-       epan_init(register_all_protocols, register_all_protocol_handoffs,
-                 NULL, NULL);
+       if (!epan_init(register_all_protocols, register_all_protocol_handoffs,
+           NULL, NULL))
+               return 2;
 
        /* set the c-language locale to the native environment. */
        setlocale(LC_ALL, "");
index 4fb797dbd7b18178ae43d0bfc2f15ff85013fa94..df4dd17ef786b8267a643db710ef79bebf8a5c17 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "config.h"
 
+#include <stdarg.h>
+
 #ifdef HAVE_LIBGCRYPT
 #include <wsutil/wsgcrypt.h>
 #endif /* HAVE_LIBGCRYPT */
 
 #include <glib.h>
 
+#include <wsutil/report_err.h>
+
+#include <epan/exceptions.h>
+
 #include "epan-int.h"
 #include "epan.h"
 #include "dfilter/dfilter.h"
@@ -85,12 +91,14 @@ epan_register_plugin_types(void)
 #endif
 }
 
-void
+gboolean
 epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
          void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
          register_cb cb,
          gpointer client_data)
 {
+       gboolean status = TRUE;
+
        /* initialize memory allocation subsystem */
        wmem_init();
 
@@ -110,20 +118,42 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
 #ifdef HAVE_LIBGNUTLS
        gnutls_global_init();
 #endif
-       tap_init();
-       prefs_init();
-       expert_init();
-       packet_init();
-       proto_init(register_all_protocols_func, register_all_handoffs_func,
-           cb, client_data);
-       packet_cache_proto_handles();
-       dfilter_init();
-       final_registration_all_protocols();
-       print_cache_field_handles();
-       expert_packet_init();
+       TRY {
+               tap_init();
+               prefs_init();
+               expert_init();
+               packet_init();
+               proto_init(register_all_protocols_func, register_all_handoffs_func,
+                   cb, client_data);
+               packet_cache_proto_handles();
+               dfilter_init();
+               final_registration_all_protocols();
+               print_cache_field_handles();
+               expert_packet_init();
 #ifdef HAVE_LUA
-       wslua_init(cb, client_data);
+               wslua_init(cb, client_data);
 #endif
+       }
+       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.
+                */
+               const char *exception_message = GET_MESSAGE;
+               static const char dissector_error_nomsg[] =
+                   "Dissector writer didn't bother saying what the error was";
+
+               report_failure("Dissector bug: %s",
+                              exception_message == NULL ?
+                                dissector_error_nomsg : exception_message);
+               if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+                       abort();
+               status = FALSE;
+       }
+       ENDTRY;
+       return status;
 }
 
 void
index 6c17964b65d8d864c561be35410b7e3c34d5b7ff..41bf18e4376bba3ce415ba930da03f574f059b75 100644 (file)
@@ -89,11 +89,17 @@ Ref2 for further edits - delete when done
  */
 WS_DLL_PUBLIC void epan_register_plugin_types(void);
 
-/** init the whole epan module, this is used to be called only once in a program */
+/**
+ * Init the whole epan module.
+ *
+ * Must be called only once in a program.
+ *
+ * Returns TRUE on success, FALSE on failure.
+ */
 WS_DLL_PUBLIC
-void epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
-              void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
-              register_cb cb, void *client_data);
+gboolean epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
+                  void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
+                  register_cb cb, void *client_data);
 
 /** cleanup the whole epan module, this is used to be called only once in a program */
 WS_DLL_PUBLIC
index c44bacef4b64b40a2f2118cc6a6b60e3077de859..0952a7c5ea77a823d8af36e6c03e8f0dcfa30d15 100644 (file)
@@ -529,7 +529,9 @@ DIAG_ON(cast-qual)
        "-G" flag, as the "-G" flag dumps information registered by the
        dissectors, and we must do it before we read the preferences, in
        case any dissectors register preferences. */
-    epan_init(register_all_protocols, register_all_protocol_handoffs, NULL, NULL);
+    if (!epan_init(register_all_protocols, register_all_protocol_handoffs,
+                   NULL, NULL))
+        return 2;
 
     prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
                          &pf_open_errno, &pf_read_errno, &pf_path);
index 47053cac99680a6d53a826ec13cc69780d2791f6..79ade49198d58a3727489fbbbc81e8ff0dbfeace 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
@@ -968,7 +968,9 @@ DIAG_ON(cast-qual)
      "-G" flag, as the "-G" flag dumps information registered by the
      dissectors, and we must do it before we read the preferences, in
      case any dissectors register preferences. */
-  epan_init(register_all_protocols, register_all_protocol_handoffs, NULL, NULL);
+  if (!epan_init(register_all_protocols, register_all_protocol_handoffs, NULL,
+                 NULL))
+    return 2;
 
   /* Register all tap listeners; we do this before we parse the arguments,
      as the "-z" argument can specify a registered tap. */
index bdab5811ca186ed85afa6b10b66f6aece9c0177e..d770bac18ce3535ef1381b71dbc53ec9cd0db188 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -1225,7 +1225,9 @@ DIAG_ON(cast-qual)
      "-G" flag, as the "-G" flag dumps information registered by the
      dissectors, and we must do it before we read the preferences, in
      case any dissectors register preferences. */
-  epan_init(register_all_protocols, register_all_protocol_handoffs, NULL, NULL);
+  if (!epan_init(register_all_protocols, register_all_protocol_handoffs, NULL,
+                 NULL))
+    return 2;
 
   /* Register all tap listeners; we do this before we parse the arguments,
      as the "-z" argument can specify a registered tap. */
index 86a357484365d94e7773d606f95a5c66c6a14453..fc871d718b9501922cc8587d8935fb2fc37e72a0 100644 (file)
@@ -2513,8 +2513,9 @@ DIAG_ON(cast-qual)
        "-G" flag, as the "-G" flag dumps information registered by the
        dissectors, and we must do it before we read the preferences, in
        case any dissectors register preferences. */
-    epan_init(register_all_protocols,register_all_protocol_handoffs,
-              splash_update, (gpointer) splash_win);
+    if (!epan_init(register_all_protocols,register_all_protocol_handoffs,
+                   splash_update, (gpointer) splash_win))
+      return 2;
 
     splash_update(RA_LISTENERS, NULL, (gpointer)splash_win);
 
index acfa7083a34081d3fecdb68028e0f34892e355a5..8e4e4633307381fd741d04f65ae5d01074a1622b 100644 (file)
@@ -836,8 +836,11 @@ DIAG_ON(cast-qual)
        "-G" flag, as the "-G" flag dumps information registered by the
        dissectors, and we must do it before we read the preferences, in
        case any dissectors register preferences. */
-    epan_init(register_all_protocols,register_all_protocol_handoffs,
-              splash_update, NULL);
+    if (!epan_init(register_all_protocols,register_all_protocol_handoffs,
+                   splash_update, NULL)) {
+        SimpleDialog::displayQueuedMessages(main_w);
+        return 2;
+    }
 
     splash_update(RA_LISTENERS, NULL, NULL);