[kaffe] Access check in getInheritedMethodIndex

Rei Odaira ray at is.s.u-tokyo.ac.jp
Tue May 17 07:46:54 PDT 2005


Hi,

I noticed that Kaffe does not correctly execute this simple program.

##################################################
package a;

public class Super {
    void test() {
	System.out.println("Super");
    }

    public static void main(String[] args) {
	((Super) new b.Sub()).test();
    }
}
##################################################
package b;

public class Sub extends a.Super {
    // This test() does not override a.Super#test(),
    // because a.Super#test() is not accessible from here.
    void test() {
	System.out.println("Sub");
    }
}
##################################################
>java a.Super
Super

>kaffe a.Super
Sub
##################################################

Attached with this mail is a jar file containing these two classes.
The JVM Spec[1] states that

  If C contains a declaration for an instance method with the same
  name and descriptor as the resolved method, and the resolved
  method is accessible from C, then this is the method to be invoked,
  and the lookup procedure terminates.

I found that an additional access check in getInheritedMethodIndex()
would fix this bug; the current code does not examine whether methods
in superclasses are accessible when building a dispatch table.

The problem here is that I cannot figure out which of the functions
should be used: checkMethodAccess() or checkAccess().

##################################################
Index: classMethod.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/classMethod.c,v
retrieving revision 1.142
diff -a -u -r1.142 classMethod.c
--- classMethod.c	14 May 2005 21:46:31 -0000	1.142
+++ classMethod.c	17 May 2005 13:57:56 -0000
@@ -1959,7 +1959,8 @@
 		Method* mt = CLASS_METHODS(super);
 		for (; --j >= 0;  ++mt) {
 			if (utf8ConstEqual (mt->name, meth->name) &&
-			    utf8ConstEqual (METHOD_SIG(mt), METHOD_SIG(meth)))
+			    utf8ConstEqual (METHOD_SIG(mt), METHOD_SIG(meth)) &&
+			    checkMethodAccess(meth->class, super, mt))
 			{
 				meth->idx = mt->idx;
 				return (true);
##################################################
Index: classMethod.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/classMethod.c,v
retrieving revision 1.142
diff -a -u -r1.142 classMethod.c
--- classMethod.c	14 May 2005 21:46:31 -0000	1.142
+++ classMethod.c	17 May 2005 13:59:29 -0000
@@ -1959,7 +1959,8 @@
 		Method* mt = CLASS_METHODS(super);
 		for (; --j >= 0;  ++mt) {
 			if (utf8ConstEqual (mt->name, meth->name) &&
-			    utf8ConstEqual (METHOD_SIG(mt), METHOD_SIG(meth)))
+			    utf8ConstEqual (METHOD_SIG(mt), METHOD_SIG(meth)) &&
+			    checkAccess(meth->class, super, mt->accflags))
 			{
 				meth->idx = mt->idx;
 				return (true);
##################################################

Any ideas?


regards,
Rei

[1] http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc6.html#invokevirtual
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.jar
Type: application/octet-stream
Size: 1186 bytes
Desc: not available
Url : http://kaffe.org/pipermail/kaffe/attachments/20050517/f6220bdf/attachment-0002.obj 


More information about the kaffe mailing list