This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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] java/13024: fix buffer overrun


Tested on i686-pc-linux-gnu.  Supposing alloca is acceptable/preferred for
variable-sized stack allocation, is this OK for mainline?

Jeff

2003-11-19  Jeff Sturm  <jsturm@one-point.com>

	Fix PR java/13024.
	* except.c (prepare_eh_table_type): Allocate variable-sized
	buffer `buf' with alloca.

Index: except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/except.c,v
retrieving revision 1.40
diff -u -p -r1.40 except.c
--- except.c	24 Oct 2003 09:29:40 -0000	1.40
+++ except.c	19 Nov 2003 04:57:52 -0000
@@ -312,6 +312,10 @@ tree
 prepare_eh_table_type (tree type)
 {
   tree exp;
+  const char *name;
+  char *buf;
+  tree decl;
+  tree utf8_ref;

   /* The "type" (match_info) in a (Java) exception table is a pointer to:
    * a) NULL - meaning match any type in a try-finally.
@@ -323,10 +327,9 @@ prepare_eh_table_type (tree type)
     exp = NULL_TREE;
   else if (is_compiled_class (type) && !flag_indirect_dispatch)
     {
-      char buf[64];
-      tree decl;
-      sprintf (buf, "%s_ref",
-	       IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
+      name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
+      buf = alloca (strlen (name) + 5);
+      sprintf (buf, "%s_ref", name);
       decl = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
       TREE_STATIC (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
@@ -342,11 +345,10 @@ prepare_eh_table_type (tree type)
     }
   else
     {
-      tree decl;
-      tree utf8_ref = build_utf8_ref (DECL_NAME (TYPE_NAME (type)));
-      char buf[64];
-      sprintf (buf, "%s_ref",
-	       IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (utf8_ref, 0))));
+      utf8_ref = build_utf8_ref (DECL_NAME (TYPE_NAME (type)));
+      name = IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (utf8_ref, 0)));
+      buf = alloca (strlen (name) + 5);
+      sprintf (buf, "%s_ref", name);
       decl = build_decl (VAR_DECL, get_identifier (buf), utf8const_ptr_type);
       TREE_STATIC (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;


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