Skip to content

Commit 844ed31

Browse files
authored
Merge pull request diffblue#288 from diffblue/bugfix/clear_most_recent_alloc_of_DOs_from_callees
SEC-163: Bugfix: Clear most-recent-alloc flag of DOs from callees
2 parents 31ae00f + 98cd3b7 commit 844ed31

File tree

3 files changed

+380
-7
lines changed

3 files changed

+380
-7
lines changed
Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,152 @@
11
package LVSA.recent_alloc_clear_from_callees;
22

3+
4+
class A {
5+
public Object data;
6+
}
7+
38
public class Test {
49
static Object output;
510

611
public static Object getData() {
712
return new Object();
813
}
914

10-
public static void main() {
15+
public static Object getData2() {
16+
return new Object();
17+
}
18+
19+
private static A getA() {
20+
return new A();
21+
}
22+
23+
private static A getA(Object o) {
24+
A a = new A();
25+
a.data = o;
26+
return a;
27+
}
28+
29+
private static Object identity(Object o) {
30+
return o;
31+
}
32+
33+
public static void should_be_most_recent() {
34+
Object d = new Object();
35+
Object e = identity(d);
36+
output = e;
37+
}
38+
39+
public static void should_be_most_recent_one_call() {
40+
output = getData();
41+
}
42+
43+
public static void should_be_most_recent_two_calls() {
44+
Object x = new Object();
45+
Object y = getData2();
1146
Object d = getData();
1247
Object e = getData();
1348
output = e;
1449
}
15-
}
1650

51+
public static void should_not_be_most_recent_two_calls() {
52+
Object x = new Object();
53+
Object y = getData2();
54+
Object d = getData();
55+
Object e = getData();
56+
output = d;
57+
}
58+
59+
public static void should_be_most_recent_local() {
60+
Object x = new Object();
61+
Object y = getData2();
62+
Object d = getData();
63+
Object e = getData();
64+
output = x;
65+
}
66+
67+
public static void should_be_most_recent_other_call() {
68+
Object x = new Object();
69+
Object y = getData2();
70+
Object d = getData();
71+
Object e = getData();
72+
output = y;
73+
}
74+
75+
public static void should_not_be_most_recent_A_1() {
76+
A d = new A();
77+
d.data = getData();
78+
Object e = getData();
79+
output = d.data;
80+
}
81+
82+
public static void should_be_most_recent_A_1() {
83+
A d = new A();
84+
d.data = getData();
85+
Object e = getData();
86+
output = e;
87+
}
88+
89+
public static void should_be_most_recent_A_2() {
90+
A d = new A();
91+
d.data = getData2();
92+
Object e = getData();
93+
output = d.data;
94+
}
95+
96+
public static void should_not_be_most_recent_A_3() {
97+
A d = getA(getData());
98+
Object e = getData();
99+
output = d.data;
100+
}
101+
102+
public static void should_be_most_recent_A_3() {
103+
A d = getA(getData());
104+
Object e = getData();
105+
output = e;
106+
}
107+
108+
public static void should_be_most_recent_A_4() {
109+
A d = getA(getData());
110+
A e = getA(getData());
111+
output = e.data;
112+
}
113+
114+
private static Object fa() {
115+
return new Object(); // Returns R
116+
}
117+
private static Object fb() {
118+
Object ret = fa();
119+
fa();
120+
return ret; // Returns *
121+
}
122+
public static void should_not_be_most_recent_caller_1() {
123+
Object recent = fa();
124+
Object should_downgrade = fb();
125+
output = should_downgrade;
126+
}
127+
public static void should_not_be_most_recent_caller_2() {
128+
Object recent = fa();
129+
Object should_downgrade = fb();
130+
output = recent;
131+
}
132+
133+
public static void should_be_most_recent_lhs_issue() {
134+
A a = getA();
135+
a.data = new Object();
136+
137+
// DO1R.data <- { DO2R }
138+
// a <- { DO1R }
139+
140+
getA();
141+
142+
// EXPECTED: DO1*.data <- { DO2R }, a <- { DO1* }
143+
// GOT: DO1R.data <- { DO2R }, a <- { DO1* }
144+
145+
Object got = a.data;
146+
147+
// EXPECTED: DO1*.data <- { DO2R }, a <- { DO1* }, got <- { DO2R }
148+
// GOT: DO1R.data <- { DO2R }, a <- { DO1* }, got { * }
149+
150+
output = got;
151+
}
152+
}

regression/LVSA/recent_alloc_clear_from_callees/test_recent_alloc_clear_from_callees.py

Lines changed: 173 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,184 @@ def _get_folder_name():
1212
return os.path.basename(_get_this_file_dir())
1313

1414

15-
@pytest.mark.xfail
16-
def test_recent_alloc_clear_from_callees(tmpdir):
15+
def test_should_be_most_recent(tmpdir):
1716
"""
18-
Checks whether 'is_most_recent_allocation' flag is cleared when
17+
[1] Checks whether 'is_most_recent_allocation' flag is cleared when
1918
receiving DOs from callees.
2019
"""
2120
with utils.working_dir(_get_this_file_dir()):
2221
os.system("javac Test.java")
23-
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('main')
22+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent')
23+
lvsa_expectation = lvsa_driver.run()
24+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
25+
value_set_expectation.check_contains_dynamic_object(1, True)
26+
27+
28+
def test_should_be_most_recent_one_call(tmpdir):
29+
"""
30+
[2] Checks whether 'is_most_recent_allocation' flag is cleared when
31+
receiving DOs from callees.
32+
"""
33+
with utils.working_dir(_get_this_file_dir()):
34+
os.system("javac Test.java")
35+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_one_call')
36+
lvsa_expectation = lvsa_driver.run()
37+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
38+
value_set_expectation.check_contains_dynamic_object(1, True)
39+
40+
41+
def test_should_be_most_recent_two_calls(tmpdir):
42+
"""
43+
[3] Checks whether 'is_most_recent_allocation' flag is cleared when
44+
receiving DOs from callees.
45+
"""
46+
with utils.working_dir(_get_this_file_dir()):
47+
os.system("javac Test.java")
48+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_two_calls')
49+
lvsa_expectation = lvsa_driver.run()
50+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
51+
value_set_expectation.check_contains_dynamic_object(1, True)
52+
53+
54+
def test_should_not_be_most_recent_two_calls(tmpdir):
55+
"""
56+
[4] Checks whether 'is_most_recent_allocation' flag is cleared when
57+
receiving DOs from callees.
58+
"""
59+
with utils.working_dir(_get_this_file_dir()):
60+
os.system("javac Test.java")
61+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_not_be_most_recent_two_calls')
2462
lvsa_expectation = lvsa_driver.run()
2563
value_set_expectation = lvsa_expectation.get_value_set_for_output()
2664
value_set_expectation.check_contains_dynamic_object(1, False)
65+
66+
67+
def test_should_be_most_recent_local(tmpdir):
68+
"""
69+
[5] Checks whether 'is_most_recent_allocation' flag is cleared when
70+
receiving DOs from callees.
71+
"""
72+
with utils.working_dir(_get_this_file_dir()):
73+
os.system("javac Test.java")
74+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_local')
75+
lvsa_expectation = lvsa_driver.run()
76+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
77+
value_set_expectation.check_contains_dynamic_object(1, True)
78+
79+
80+
def test_should_be_most_recent_other_call(tmpdir):
81+
"""
82+
[6] Checks whether 'is_most_recent_allocation' flag is cleared when
83+
receiving DOs from callees.
84+
"""
85+
with utils.working_dir(_get_this_file_dir()):
86+
os.system("javac Test.java")
87+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_other_call')
88+
lvsa_expectation = lvsa_driver.run()
89+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
90+
value_set_expectation.check_contains_dynamic_object(1, True)
91+
92+
93+
def test_should_not_be_most_recent_A_1(tmpdir):
94+
"""
95+
[7] Checks whether 'is_most_recent_allocation' flag is cleared when
96+
receiving DOs from callees.
97+
"""
98+
with utils.working_dir(_get_this_file_dir()):
99+
os.system("javac Test.java")
100+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_not_be_most_recent_A_1')
101+
lvsa_expectation = lvsa_driver.run()
102+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
103+
value_set_expectation.check_contains_dynamic_object(1, False)
104+
105+
106+
def test_should_be_most_recent_A_2(tmpdir):
107+
"""
108+
[8] Checks whether 'is_most_recent_allocation' flag is cleared when
109+
receiving DOs from callees.
110+
"""
111+
with utils.working_dir(_get_this_file_dir()):
112+
os.system("javac Test.java")
113+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_A_2')
114+
lvsa_expectation = lvsa_driver.run()
115+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
116+
value_set_expectation.check_contains_dynamic_object(1, True)
117+
118+
119+
def test_should_not_be_most_recent_A_3(tmpdir):
120+
"""
121+
[9] Checks whether 'is_most_recent_allocation' flag is cleared when
122+
receiving DOs from callees.
123+
"""
124+
with utils.working_dir(_get_this_file_dir()):
125+
os.system("javac Test.java")
126+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_not_be_most_recent_A_3')
127+
lvsa_expectation = lvsa_driver.run()
128+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
129+
value_set_expectation.check_contains_dynamic_object(1, False)
130+
131+
132+
def test_should_be_most_recent_A_3(tmpdir):
133+
"""
134+
[10] Checks whether 'is_most_recent_allocation' flag is cleared when
135+
receiving DOs from callees.
136+
"""
137+
with utils.working_dir(_get_this_file_dir()):
138+
os.system("javac Test.java")
139+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_A_3')
140+
lvsa_expectation = lvsa_driver.run()
141+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
142+
value_set_expectation.check_contains_dynamic_object(1, True)
143+
144+
145+
def test_should_be_most_recent_A_4(tmpdir):
146+
"""
147+
[11] Checks whether 'is_most_recent_allocation' flag is cleared when
148+
receiving DOs from callees.
149+
"""
150+
with utils.working_dir(_get_this_file_dir()):
151+
os.system("javac Test.java")
152+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_A_4')
153+
lvsa_expectation = lvsa_driver.run()
154+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
155+
value_set_expectation.check_contains_dynamic_object(1, True)
156+
157+
158+
def test_should_not_be_most_recent_caller_1(tmpdir):
159+
"""
160+
[12] Checks whether 'is_most_recent_allocation' flag is cleared when
161+
receiving DOs from callees.
162+
"""
163+
with utils.working_dir(_get_this_file_dir()):
164+
os.system("javac Test.java")
165+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_not_be_most_recent_caller_1')
166+
lvsa_expectation = lvsa_driver.run()
167+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
168+
value_set_expectation.check_contains_dynamic_object(1, False)
169+
170+
171+
@pytest.mark.xfail(strict=True)
172+
def test_should_not_be_most_recent_caller_2(tmpdir):
173+
"""
174+
[13] Checks whether 'is_most_recent_allocation' flag is cleared when
175+
receiving DOs from callees.
176+
"""
177+
with utils.working_dir(_get_this_file_dir()):
178+
os.system("javac Test.java")
179+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_not_be_most_recent_caller_2')
180+
lvsa_expectation = lvsa_driver.run()
181+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
182+
value_set_expectation.check_contains_dynamic_object(1, False)
183+
184+
185+
def test_should_be_most_recent_lhs_issue(tmpdir):
186+
"""
187+
[14] Checks whether 'is_most_recent_allocation' flag is cleared when
188+
receiving DOs from callees.
189+
"""
190+
with utils.working_dir(_get_this_file_dir()):
191+
os.system("javac Test.java")
192+
lvsa_driver = driver.LvsaDriver(tmpdir, _get_folder_name()).with_test_function('should_be_most_recent_lhs_issue')
193+
lvsa_expectation = lvsa_driver.run()
194+
value_set_expectation = lvsa_expectation.get_value_set_for_output()
195+
value_set_expectation.check_contains_dynamic_object(1, True)

0 commit comments

Comments
 (0)