This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 01/02] jit-builtins.c: Fix segfault on unsupported builtins


jit-builtins.c only supports a subset of builtin-types.def, and
can fail if the user requests a builtin that uses the unsupported
types.

Whilst fixing PR jit/64020 I noticed that these failures read through
NULL and segfault.

Fix it by checking for get_type and make_builtin_function returning
NULL (which happens for a builtin_id that uses an unsupported type).

gcc/jit/ChangeLog:
	* jit-builtins.c
	(gcc::jit::recording::builtins_manager::get_builtin_function):
	Check for NULL return from make_builtin_function.
	(gcc::jit::recording::builtins_manager::make_builtin_function):
	Check for NULL return from get_type.
---
 gcc/jit/jit-builtins.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c
index 49d37d8..9063075 100644
--- a/gcc/jit/jit-builtins.c
+++ b/gcc/jit/jit-builtins.c
@@ -160,8 +160,12 @@ builtins_manager::get_builtin_function (const char *name)
      the same id on a context give back the same object.  */
   if (!m_builtin_functions[builtin_id])
     {
-      m_builtin_functions[builtin_id] = make_builtin_function (builtin_id);
-      m_ctxt->record (m_builtin_functions[builtin_id]);
+      function *fn = make_builtin_function (builtin_id);
+      if (fn)
+	{
+	  m_builtin_functions[builtin_id] = fn;
+	  m_ctxt->record (fn);
+	}
     }
 
   return m_builtin_functions[builtin_id];
@@ -174,7 +178,10 @@ builtins_manager::make_builtin_function (enum built_in_function builtin_id)
 {
   const struct builtin_data& bd = builtin_data[builtin_id];
   enum jit_builtin_type type_id = bd.type;
-  function_type *func_type = get_type (type_id)->as_a_function_type ();
+  type *t = get_type (type_id);
+  if (!t)
+    return NULL;
+  function_type *func_type = t->as_a_function_type ();
   if (!func_type)
     return NULL;
 
-- 
1.8.5.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]