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: FYI: fix for obscure SEGV in boehm.cc


I'm checking this in.

It turns out that _Jv_MarkObj can crash in an obscure situation.  If
the GC decides to collect during a call to JvAllocObject(Class,...),
we can run into a class object which has been allocated but not filled
in.  In particular Class.name is NULL, meaning that Class.isArray()
will SEGV.

Tom

2002-09-25  Tom Tromey  <tromey@redhat.com>

	* boehm.cc (_Jv_MarkObj): Don't fail if class object has been
	allocated but not initialized.

Index: boehm.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/boehm.cc,v
retrieving revision 1.33
diff -u -r1.33 boehm.cc
--- boehm.cc 12 Feb 2002 04:14:52 -0000 1.33
+++ boehm.cc 25 Sep 2002 20:10:57 -0000
@@ -1,6 +1,6 @@
 // boehm.cc - interface between libjava and Boehm GC.
 
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -134,6 +134,12 @@
       p = (ptr_t) c->methods;
       MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c, c6label);
 
+      // The vtable might have been set, but the rest of the class
+      // could still be uninitialized.  If this is the case, then
+      // c.isArray will SEGV.  We check for this, and if it is the
+      // case we just return.
+      if (__builtin_expect (c->name == NULL, false))
+	return mark_stack_ptr;
 
       if (! c->isArray() && ! c->isPrimitive())
 	{


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