Skip to content

[SEC-180] Overlay classes #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added regression/cbmc-java/invalid_classpath/Test.class
Binary file not shown.
3 changes: 3 additions & 0 deletions regression/cbmc-java/invalid_classpath/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Test {
public void main() {}
}
10 changes: 10 additions & 0 deletions regression/cbmc-java/invalid_classpath/test-jar.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--classpath ./NotHere.jar
^EXIT=6$
^SIGNAL=0$
^the program has no entry point$
^failed to load class `Test'$
--
--
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
10 changes: 10 additions & 0 deletions regression/cbmc-java/invalid_classpath/test-path.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--classpath ./NotHere
^EXIT=6$
^SIGNAL=0$
^the program has no entry point$
^failed to load class `Test'$
--
--
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
Binary file added regression/cbmc-java/overlay-class/Test.class
Binary file not shown.
14 changes: 14 additions & 0 deletions regression/cbmc-java/overlay-class/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Test
{
public int x;

public static void main(String[] args)
{
assert(false);
}

public static void notOverlain()
{
assert(true);
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.diffblue;

public @interface OverlayClassImplementation {
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.diffblue;

public @interface OverlayMethodImplementation {
}
Binary file not shown.
14 changes: 14 additions & 0 deletions regression/cbmc-java/overlay-class/correct-overlay/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import com.diffblue.OverlayClassImplementation;
import com.diffblue.OverlayMethodImplementation;

@OverlayClassImplementation
public class Test
{
public int x;

@OverlayMethodImplementation
public static void main(String[] args)
{
assert(true);
}
}
17 changes: 17 additions & 0 deletions regression/cbmc-java/overlay-class/correct-test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CORE
Test.class
--classpath `./format_classpath.sh . annotations correct-overlay` --verbosity 10
^Getting class `Test' from file \.[\\/]Test\.class$
^Getting class `Test' from file correct-overlay[\\/]Test\.class$
^Adding symbol from overlay class: field 'x'$
^Adding symbol from overlay class: method 'java::Test\.<init>:\(\)V'$
^Field definition for java::Test\.x already loaded from overlay class$
^Adding symbol from overlay class: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
^Method java::Test\.<init>:\(\)V exists in an overlay class without being marked as an overlay and also exists in the underlying class
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
17 changes: 17 additions & 0 deletions regression/cbmc-java/overlay-class/duplicate-test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CORE
Test.class
--classpath `./format_classpath.sh . annotations . correct-overlay` --verbosity 10
^Getting class `Test' from file \.[\\/]Test\.class$
^Getting class `Test' from file correct-overlay[\\/]Test\.class$
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
^Adding symbol from overlay class: field 'x'$
^Adding symbol from overlay class: method 'java::Test\.<init>:\(\)V'$
^Field definition for java::Test\.x already loaded from overlay class$
^Adding symbol from overlay class: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
^Method java::Test\.<init>:\(\)V exists in an overlay class without being marked as an overlay and also exists in the underlying class
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
12 changes: 12 additions & 0 deletions regression/cbmc-java/overlay-class/format_classpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

unameOut="$(uname -s)"
case "${unameOut}" in
CYGWIN*) separator=";";;
MINGW*) separator=";";;
MSYS*) separator=";";;
Windows*) separator=";";;
*) separator=":"
esac

echo -n `IFS=$separator; echo "$*"`
16 changes: 16 additions & 0 deletions regression/cbmc-java/overlay-class/misordered-test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CORE
Test.class
--classpath `./format_classpath.sh annotations correct-overlay .` --verbosity 10
^Getting class `Test' from file correct-overlay[\\/]Test\.class$
^Getting class `Test' from file \.[\\/]Test\.class$
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
^Adding symbol: field 'x'$
^Adding symbol: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
^VERIFICATION FAILED$
^EXIT=10$
^SIGNAL=0$
--
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
^Adding symbol from overlay class
exists in an overlay class without being marked as an overlay and also exists in the underlying class
Binary file not shown.
11 changes: 11 additions & 0 deletions regression/cbmc-java/overlay-class/unmarked-overlay/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import com.diffblue.OverlayClassImplementation;
import com.diffblue.OverlayMethodImplementation;

public class Test
{
@OverlayMethodImplementation
public static void main(String[] args)
{
assert(false);
}
}
16 changes: 16 additions & 0 deletions regression/cbmc-java/overlay-class/unmarked-test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CORE
Test.class
--classpath `./format_classpath.sh . annotations unmarked-overlay` --verbosity 10
^Getting class `Test' from file \.[\\/]Test\.class$
^Getting class `Test' from file unmarked-overlay[\\/]Test\.class$
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
^Adding symbol: field 'x'$
^Adding symbol: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
^VERIFICATION FAILED$
^EXIT=10$
^SIGNAL=0$
--
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
^Adding symbol from overlay class
exists in an overlay class without being marked as an overlay and also exists in the underlying class
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package java.lang;

public class Object {
public final Class<?> getClass() {
return null;
}

public int hashCode() { return 0; }

public boolean equals(Object obj) { return (this == obj); }

protected Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}

public String toString() { return "object"; }

public final void notify() {}

public final void notifyAll() {}

public final void wait(long timeout) throws InterruptedException {
throw new InterruptedException();
}

public final void wait(long timeout, int nanos) throws InterruptedException {
wait(timeout);
}

public final void wait() throws InterruptedException { wait(0); }

protected void finalize() throws Throwable { }
}
10 changes: 10 additions & 0 deletions regression/cbmc-java/provide_object_implementation/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE symex-driven-lazy-loading-expected-failure
java/lang/Object.class

^EXIT=6$
^SIGNAL=0$
^the program has no entry point$
--
^failed to add class symbol java::java\.lang\.Object$
--
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
12 changes: 6 additions & 6 deletions src/java_bytecode/ci_lazy_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ bool ci_lazy_methodst::operator()(
reachable_classes.push_back(main_class);
else
reachable_classes = main_jar_classes;
for(const auto &classname : reachable_classes)
for(const irep_idt &class_name : reachable_classes)
{
const auto &methods=
java_class_loader.class_map.at(classname).parsed_class.methods;
const auto &methods =
java_class_loader.get_original_class(class_name).parsed_class.methods;
for(const auto &method : methods)
{
const irep_idt methodid="java::"+id2string(classname)+"."+
id2string(method.name)+":"+
id2string(method.descriptor);
const irep_idt methodid =
"java::" + id2string(class_name) + "." + id2string(method.name)
+ ":" + id2string(method.descriptor);
method_worklist2.push_back(methodid);
}
}
Expand Down
Loading