public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bryce McKinlay <bmckinlay@gmail.com>
To: Erik Groeneveld <erik@cq2.nl>
Cc: Andrew Haley <aph@redhat.com>, java <java@gcc.gnu.org>
Subject: Re: problem with class accessiblity check in invoke (natMethod.cc)
Date: Wed, 23 Dec 2009 15:09:00 -0000	[thread overview]
Message-ID: <7230133d0912230709r4aaa858du760202283165869f@mail.gmail.com> (raw)
In-Reply-To: <aaec99390912230534s5a162f00waadadc2547e888f2@mail.gmail.com>

On Wed, Dec 23, 2009 at 1:34 PM, Erik Groeneveld <erik@cq2.nl> wrote:

> The following code demonstrates the problem.
>
> #include <gcj/cni.h>
> #include <java/util/ArrayList.h>
> #include <java/util/Iterator.h>
> #include <java/lang/reflect/Method.h>
> #include <stdio.h>
>
> int main(int argc, char* argv[]) {
>    JvCreateJavaVM(NULL);
>    JvAttachCurrentThread(NULL, NULL);
>    java::util::ArrayList* l = new java::util::ArrayList();
>    java::util::Iterator* i = l->iterator();
>    java::lang::reflect::Method* m = i->getClass()->getDeclaredMethod(
>            JvNewStringUTF("hasNext"), NULL);
>    printf("calling invoke, it'll dump core in natMethod.cc line 194\n");
>    m->invoke(i, NULL);
>    return 0;
> }
>
> $gcc problem.cpp -lgcj
> $./a.out
> calling invoke
> Aborted (core dumped)
>
> $gdb -core core a.out
> (gdb) where
> #0  0x00002adf9252bed5 in raise () from /lib/libc.so.6
> #1  0x00002adf9252d3f3 in abort () from /lib/libc.so.6
> #2  0x00002adf90bdeed8 in _Jv_Throw (value=0x2adf932cd370) at
> ../../../src/libjava/exception.cc:128
> #3  0x00002adf90bd2a2a in _Jv_catch_segv (_p=<value optimized out>) at
> ../../../src/libjava/prims.cc:184
> #4  <signal handler called>
> #5  0x00002adf90c217d3 in java::lang::reflect::Method::invoke
> (this=0x2adf932d1c80, obj=0x2adf93ba6e40,
>    args=0x0) at ../../../src/libjava/java/lang/reflect/natMethod.cc:194
> #6  0x0000000000400a5c in main ()
>
> The top of the stack is from the NULL-pointer catching signal handler
> we believe, so #5 and #6 are the relevant ones.
>
> The point is that we believe that the scenario in the C++ code is
> valid, both from Java and from C++, and we do not see the reasons for
> the additional check that has been added to the invoke() method.

Method.invoke() is required to check accessibility according to the
Java Language Specification, so this check is required.

The only thing libgcj is doing wrong is failing to check for null
"caller" (which can't happen in Java code). It should probably do this
check and throw an IllegalAccessException, or maybe just permit the
access.

A workaround is to just add a Method.setAccessible() call to your code
to bypass access checks.

Bryce

  reply	other threads:[~2009-12-23 15:09 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
2009-12-23 13:34   ` Erik Groeneveld
2009-12-23 15:09     ` Bryce McKinlay [this message]
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=7230133d0912230709r4aaa858du760202283165869f@mail.gmail.com \
    --to=bmckinlay@gmail.com \
    --cc=aph@redhat.com \
    --cc=erik@cq2.nl \
    --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).