public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: java@gcc.gnu.org
Subject: Re: problem with class accessiblity check in invoke (natMethod.cc)
Date: Wed, 23 Dec 2009 10:47:00 -0000	[thread overview]
Message-ID: <4B31F521.1010404@redhat.com> (raw)
In-Reply-To: <aaec99390912230238s2fa25e4buac3bfbab679e8d92@mail.gmail.com>

On 12/23/2009 10:38 AM, Erik Groeneveld wrote:

> We recently upgraded from libgcj7 to libgcj9. This broke our code. We
> found out that in natMethod.cc in invoke() there is an additional
> check for class accessibility. It starts out with:
> 
>   // Check accessibility, if required.
>   if (! this->isAccessible())
>     {
>       if (! (Modifier::isPublic (meth->accflags)))
> 	{
> 	  Class *caller = _Jv_StackTrace::GetCallingClass (&Method::class$);
> 	  if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
> 	    throw new IllegalAccessException;
> 	}
> 
> and then continues here (this part is new):
> 
>       else
> 	// Method is public, check to see if class is accessible.
> 	{
> 	  jint flags = (declaringClass->accflags
> 			& (Modifier::PUBLIC
> 			   | Modifier::PROTECTED
> 			   | Modifier::PRIVATE));
> 	  if (flags == 0) // i.e. class is package private
> 	    {
> 	      Class *caller = _Jv_StackTrace::GetCallingClass (&Method::class$);
> 	      if (! _Jv_ClassNameSamePackage (caller->name,
> 					      declaringClass->name))
> 		throw new IllegalAccessException;
> 	    }
> 	}
>     }
> 
> The added code prevents legal calls to fail. For example, it is no
> longer possible to call invoke on the ´hasNext´ method on the iterator
> from AbstractList.  The method AbstractList.iterator() returns an
> anonymous innerclass object which according to the C code above is not
> accessible since it is package private.  There are two problems here:
> 
> 1. The systems segfaults on the caller->name because there is no calling class.

How can there be no calling class?

> 2. We believe class accessibility is not relevant here: there is no
> reason why a Method object with public access should not be invokable,
> or is there?
> 
> We found the following modification log, which is why we address
> Andrew Haley directly as well as the list:
> 
> 2007-04-16  Andrew Haley  <aph@redhat.com>
> 
>         * java/lang/reflect/natMethod.cc (Method::invoke): In invoke also
>         check that the method's declaring class is accessible.
> 
> Can you or anybody else explain why this was considered to be necessary?

Yes, but can you send a test case before we go any further?  Then at least
we'll all know what you're talking about.

Andrew.

  reply	other threads:[~2009-12-23 10:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-23 10:38 Erik Groeneveld
2009-12-23 10:47 ` Andrew Haley [this message]
2009-12-23 13:34   ` Erik Groeneveld
2009-12-23 15:09     ` Bryce McKinlay
2009-12-23 16:39       ` Erik Groeneveld
     [not found]       ` <C62FFC62-326C-49A1-893F-3181BC4C3DCD@cq2.nl>
2009-12-23 16:44         ` Bryce McKinlay
2009-12-23 18:09           ` Erik Groeneveld
2009-12-23 18:45             ` Andrew Haley
2009-12-23 20:57               ` Erik Groeneveld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B31F521.1010404@redhat.com \
    --to=aph@redhat.com \
    --cc=java@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).