Re: [Lit.] Buffer overruns
From: David Wagner (daw_at_taverner.cs.berkeley.edu)
Date: 01/20/05
- Next message: Bruce Stephens: "Re: Factoring problem, solved"
- Previous message: Lits O'Hate: "Re: Surrogate factoring, update on research"
- In reply to: Paul Rubin: "Re: [Lit.] Buffer overruns"
- Next in thread: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 19 Jan 2005 23:56:02 +0000 (UTC)
Paul Rubin wrote:
>I didn't realize it either. I thought that Java enforced private
>instance variables at all times. It looks like at least there's a
>convenient way to turn the protection ON.
I do know of one other way that the Java compiler fails to enforce
private instance variables: inner classes. Consider code like this:
public class Foo {
private int x;
Foo() { ... }
public class Bar {
Bar() { ... }
public void barMethod() { ... }
}
}
(I hope I got the syntax right.)
Obviously, the methods in Bar have access to 'x'. How do they get
that access? It turns out that the javac compiler transforms the
above code into a class Foo and another separate class called something
like Foo$Bar. This transformation is done because (I believe) JVML byte
code does not have any notion of nested classes. Then Foo$Bar needs
access to 'x', but because Foo$Bar is not a public class, it doesn't get
access by default. So what the compiler does is put Foo$Bar in the same
package as Foo and change the scope modifier on 'Foo.x' to be 'protected'
instead of 'private' so that Foo$Bar can access 'x'. Of course, this
has the undesireable consequence of allowing anyone else in the same
package as Foo to also access 'x', which is lame. However, this is
not a flaw of the JVML byte code or even (arguably) of the Java language,
so much as a flaw of javac's compilation strategy, I think.
As you say, the good news is that at least you can arrange to check
that these cheesy ways to subvert the type system are turned off. It
is a pretty easy syntactic check. Once you have confirmed that these
visibility holes are disabled, then you can do modular verification.
In contrast, in C the corresponding checks needed before you can do
modular verification are much harder. (For instance, they involve at
a minimum verifying that none of the code has any buffer overruns anywhere,
which is pretty much beyond the state of the art today unless you are
using some runtime system that provides automatic bounds checking.)
- Next message: Bruce Stephens: "Re: Factoring problem, solved"
- Previous message: Lits O'Hate: "Re: Surrogate factoring, update on research"
- In reply to: Paul Rubin: "Re: [Lit.] Buffer overruns"
- Next in thread: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|