Catch attempts to pass unregistered protocols to prefs routines.
authorGuy Harris <guy@alum.mit.edu>
Sat, 15 Apr 2017 21:45:12 +0000 (14:45 -0700)
committerGuy Harris <guy@alum.mit.edu>
Sat, 15 Apr 2017 21:46:55 +0000 (21:46 +0000)
That way, you don't end up with "(none)" being used as the filter name
and getting confusing error messages.

Change-Id: Ifc77d4434d82dabebe74118742938cfa5234791d
Reviewed-on: https://code.wireshark.org/review/21118
Reviewed-by: Guy Harris <guy@alum.mit.edu>
epan/prefs.c

index 5e0b8e6268643c08c88c79a43b6ce10d6a97de6f..71bf84b75136ad9eece5817fee512177a29b5434 100644 (file)
@@ -594,6 +594,8 @@ prefs_register_protocol(int id, void (*apply_cb)(void))
         prefs_register_modules();
     }
     protocol = find_protocol_by_id(id);
+    if (protocol == NULL)
+        g_error("Protocol preferences being registered with an invalid protocol ID");
     return prefs_register_module(protocols_module,
                                  proto_get_protocol_filter_name(id),
                                  proto_get_protocol_short_name(protocol),
@@ -604,6 +606,8 @@ void
 prefs_deregister_protocol (int id)
 {
     protocol_t *protocol = find_protocol_by_id(id);
+    if (protocol == NULL)
+        g_error("Protocol preferences being de-registered with an invalid protocol ID");
     prefs_deregister_module (protocols_module,
                              proto_get_protocol_filter_name(id),
                              proto_get_protocol_short_name(protocol));
@@ -662,6 +666,8 @@ prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(vo
     }
 
     protocol = find_protocol_by_id(id);
+    if (protocol == NULL)
+        g_error("Protocol subtree being registered with an invalid protocol ID");
     return prefs_register_module(subtree_module,
                                  proto_get_protocol_filter_name(id),
                                  proto_get_protocol_short_name(protocol),
@@ -691,6 +697,8 @@ prefs_register_protocol_obsolete(int id)
         prefs_register_modules();
     }
     protocol = find_protocol_by_id(id);
+    if (protocol == NULL)
+        g_error("Protocol being registered with an invalid protocol ID");
     module = prefs_register_module(protocols_module,
                                    proto_get_protocol_filter_name(id),
                                    proto_get_protocol_short_name(protocol),