diff mbox

RFA: Fail gracefully when registering info for an unknown plugin

Message ID 874m47nlwf.fsf@redhat.com
State New
Headers show

Commit Message

Nick Clifton Oct. 20, 2016, 2:19 p.m. UTC
Hi Guys,

  Whilst experimenting with writing a plugin for gcc I discovered that
  I could cause a segfault if I attempted to register a PLUGIN_INFO
  callback with any name other than the name of the plugin.  The
  attached patch fixes this problem and produces an error message
  instead.

  OK to apply ?

Cheers
  Nick

gcc/ChangeLog
2016-10-20  Nick Clifton  <nickc@redhat.com>

	* plugin.c (register_plugin_info): Produce an error message if the
	plugin is not found in the hash table.

Comments

Jeff Law Oct. 24, 2016, 3:15 p.m. UTC | #1
On 10/20/2016 08:19 AM, Nick Clifton wrote:
> Hi Guys,
>
>   Whilst experimenting with writing a plugin for gcc I discovered that
>   I could cause a segfault if I attempted to register a PLUGIN_INFO
>   callback with any name other than the name of the plugin.  The
>   attached patch fixes this problem and produces an error message
>   instead.
>
>   OK to apply ?
>
> Cheers
>   Nick
>
> gcc/ChangeLog
> 2016-10-20  Nick Clifton  <nickc@redhat.com>
>
> 	* plugin.c (register_plugin_info): Produce an error message if the
> 	plugin is not found in the hash table.
OK.
jeff
diff mbox

Patch

Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 241361)
+++ gcc/plugin.c	(working copy)
@@ -330,7 +330,15 @@ 
 register_plugin_info (const char* name, struct plugin_info *info)
 {
   void **slot = htab_find_slot (plugin_name_args_tab, name, NO_INSERT);
-  struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
+  struct plugin_name_args *plugin;
+
+  if (slot == NULL)
+    {
+      error ("unable to register info for plugin '%s' - plugin name not found",
+	     name);
+      return;
+    }
+  plugin = (struct plugin_name_args *) *slot;
   plugin->version = info->version;
   plugin->help = info->help;
 }