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]

C++ PATCH: check catch parameter


Hi,
We currently don't validate the type of a catch parameter, (it cannot be
incomplete or pointer/ref to incomplete other than cv void) and hence either
accept bogus code, or die trying.

Similarly to my recent patch to build_throw, this checks
process_start_catch_block.

Ok to install?

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
1999-06-06  Nathan Sidwell  <nathan@acm.org>

	* except.c (process_start_catch_block): Validate catch parameter type.

*** ../mainline/egcs/gcc/cp/except.c	Fri Jun  4 09:25:05 1999
--- egcs/gcc/cp/except.c	Sun Jun  6 23:35:10 1999
*************** process_start_catch_block (declspecs, de
*** 625,630 ****
--- 629,657 ----
  
        if (decl == NULL_TREE)
  	error ("invalid catch parameter");
+       else
+         {
+           tree t = TREE_TYPE (decl);
+   
+           /* Cannot throw an incomplete type. */
+           if (!complete_type_or_else (t, NULL_TREE))
+             decl = NULL_TREE;
+           else
+             {
+               /* Or a pointer or ref to one, other than cv void *.  */
+               int is_ptr = TREE_CODE (t) == POINTER_TYPE;
+               if (is_ptr || TREE_CODE (t) == REFERENCE_TYPE)
+                 {
+                   t = TREE_TYPE (t);
+                   
+                   if (is_ptr && same_type_p (TYPE_MAIN_VARIANT (t),
+                                              void_type_node))
+                     /* OK */;
+                   else if (!complete_type_or_else (t, NULL_TREE))
+                     decl = NULL_TREE;
+                 }
+             }
+         }
      }
  
    if (decl)
// Build don't link:
// 
// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 6 Jun 1999 <nathan@acm.org>

// We cannot catch an incomplete type, or ptr to one

struct A; // ERROR - forward decl

void fn()
{
  try {}
  catch (A *p) {} // ERROR - undefined type
  try {}
  catch (A p) {}  // ERROR - undefined type
  try {}
  catch (void const *p) {}  // ok
}

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