Skip to content

[SEC-180] Add ability to overlay classes with new definitions of existing methods #1816

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
Mar 27, 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
6 changes: 3 additions & 3 deletions regression/cbmc-java/generics_type_param/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ GenericFields$SimpleGenericField.class
--cover location --function GenericFields\$SimpleGenericField.foo --verbosity 10
^EXIT=0$
^SIGNAL=0$
Reading class AWrapper
Reading class FWrapper
Reading class IWrapper
Parsing class AWrapper
Parsing class FWrapper
Parsing class IWrapper
--
failed to load class \`AWrapper\'
failed to load class \`FWrapper\'
Expand Down
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might consider pulling this into a separate repo so you don't have to keep providing implementations of these OverlayMethod/Class attributes.

}
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)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this test more robust I'd probably put an assert(true) here an an assert(false) in the other original one.

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
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