Skip to content

Commit 7a6359c

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#353 from diffblue/owen-jones-diffblue/improve-common-libraries-handling-security-analyser
Improve the handling of common libraries in security analyser
2 parents d7142e9 + 28aaf54 commit 7a6359c

File tree

4 files changed

+53
-37
lines changed

4 files changed

+53
-37
lines changed

benchmarks/LIBRARIES/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apache-tomcat-9
22
openjdk-8
3+
oracle-jdk-8
34
spring-framework
45

benchmarks/LIBRARIES/README.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ of the sub-libraries:
3434
allows you to later remove/adopt/substitute some desired parts
3535
of the library.
3636

37+
Where to find JAR with javax.crypto.*:
38+
- This is not in OpenJDK. It is only in the Oracle's JDK, see:
39+
https://stackoverflow.com/questions/14935447/why-am-i-getting-package-javax-crypto-does-not-exist
40+
- The package can be downloaded from:
41+
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html#JCE-1_2_2-G-JS
42+
43+
3744
Alternative installation:
3845

3946
1. Download OpenJDK 8 .deb package, e.g. from:
@@ -45,6 +52,18 @@ Alternative installation:
4552
4. Copy the found "rt.jar" file into the created directory "openjdk-8".
4653

4754

55+
IMPORTANT NOTE: In order to analyse Sakai, we need to use Oracle's JDK 8,
56+
because these packages are missing in the OpenJDK:
57+
javax.crypto.*
58+
sun.invoke.*
59+
com.sum.jmx.*
60+
You can download Oracle's JDK here:
61+
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
62+
Then, you need to take these JARs from the directory 'jre/lib':
63+
rt.jar
64+
jce.jar
65+
66+
4867
(2) Apache Tomcat 9
4968
-------------------
5069

driver/mkbench.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def collect_java_binaries(app_path, list_of_classpaths, entry_point, temp_dir, o
9191
java_binaries = CollectedJavaBinaries()
9292
_find_java_binaries(app_path, java_binaries)
9393

94+
java_libraries = CollectedJavaBinaries()
95+
for path in list_of_classpaths:
96+
if os.path.isdir(path):
97+
_find_java_binaries(path, java_libraries)
98+
9499
prof["num_classes"] = len(java_binaries.class_files)
95100
prof["num_classpath_jar_files"] = len(java_binaries.classpath_jar_files)
96101

@@ -135,7 +140,7 @@ def collect_java_binaries(app_path, list_of_classpaths, entry_point, temp_dir, o
135140
with open(output_json, "w") as ofile:
136141
ofile.write(json.dumps({
137142
"jar": java_binaries.jar_file,
138-
"classpath": sorted([p for p in list_of_classpaths + java_binaries.classpath_jar_files if os.path.exists(p)]),
143+
"classpath": [p for p in java_binaries.classpath_jar_files + java_libraries.classpath_jar_files + list_of_classpaths if os.path.exists(p)],
139144
"entry-point": entry_point
140145
}, sort_keys=True, indent=4))
141146

driver/run.py

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,43 @@ def _get_my_dir(): return os.path.dirname(os.path.realpath(__file__))
1515
def _get_common_libraries():
1616

1717
def get_benchmark_library_dir():
18-
return os.path.join(_get_my_dir(), "../benchmarks/LIBRARIES")
18+
return os.path.abspath(os.path.join(_get_my_dir(), "../benchmarks/LIBRARIES"))
1919

2020
def get_diffblue_models_library_props():
21-
props = {"diffblue_models_library": {"directory": None, "files": [], "error": None}}
22-
directory = os.path.join(get_benchmark_library_dir(), "models/model/target")
23-
if os.path.isdir(directory):
24-
props["diffblue_models_library"]["directory"] = directory
25-
pathname = os.path.join(directory, "models.jar")
26-
if os.path.isfile(pathname):
27-
props["diffblue_models_library"]["files"].append(pathname)
28-
else:
29-
props["diffblue_models_library"]["error"] = "Cannot access Diffblue Models Library's file " + pathname
21+
props = {"diffblue_models_library": {"paths": [], "error": None}}
22+
pathname = os.path.join(get_benchmark_library_dir(), "models", "model", "target", "models.jar")
23+
if os.path.isfile(pathname):
24+
props["diffblue_models_library"]["paths"].append(pathname)
25+
else:
26+
props["diffblue_models_library"]["error"] = "Cannot access Diffblue Models Library's file " + pathname
27+
return props
28+
pathname = os.path.join(get_benchmark_library_dir(), "oracle-jdk-8")
29+
if os.path.isdir(pathname):
30+
props["diffblue_models_library"]["paths"].append(pathname)
3031
else:
31-
props["diffblue_models_library"]["error"] = "Cannot access Diffblue Models Library's directory " + directory
32+
pathname = os.path.join(get_benchmark_library_dir(), "openjdk-8")
33+
if os.path.isdir(pathname):
34+
props["diffblue_models_library"]["paths"].append(pathname)
35+
else:
36+
print("Warning: cannot access JDK install directory " + pathname)
3237
return props
3338

3439
def get_apache_tomcat_props():
35-
props = {"apache_tomcat": {"directory": None, "files": [], "error": None}}
36-
directory = os.path.join(get_benchmark_library_dir(), "apache-tomcat-9/lib")
40+
props = {"apache_tomcat": {"paths": [], "error": None}}
41+
directory = os.path.join(get_benchmark_library_dir(), "apache-tomcat-9", "lib")
3742
if os.path.isdir(directory):
38-
props["apache_tomcat"]["directory"] = directory
39-
pathname = os.path.join(directory, "servlet-api.jar")
40-
if os.path.isfile(pathname):
41-
props["apache_tomcat"]["files"].append(pathname)
42-
else:
43-
props["apache_tomcat"]["error"] = "Cannot access Apache Tomcat's file " + pathname
43+
props["apache_tomcat"]["paths"].append(directory)
4444
else:
4545
props["apache_tomcat"]["error"] = "Cannot access Apache Tomcat's directory " + directory
4646
return props
4747

4848
def get_spring_framework_props():
49-
props = {"spring_framework": {"directory": None, "files": [], "error": None}}
50-
directory = os.path.join(get_benchmark_library_dir(), "spring-framework/libs")
49+
props = {"spring_framework": {"paths": [], "error": None}}
50+
directory = os.path.join(get_benchmark_library_dir(), "spring-framework", "libs")
5151
if os.path.isdir(directory):
52-
props["spring_framework"]["directory"] = directory
53-
required_fname_prefixes = ["spring-core-", "spring-beans-"]
5452
for fname in os.listdir(directory):
55-
if (fname.endswith(".RELEASE.jar") and any(fname.startswith(x) for x in required_fname_prefixes)):
56-
props["spring_framework"]["files"].append(os.path.join(directory, fname))
57-
if len(props["spring_framework"]["files"]) != 2:
58-
props["spring_framework"]["error"] = (
59-
"There are missing JAR files in Spring Framework's directory " + directory + "\n"
60-
"These were found:\n " +
61-
"\n ".join([os.path.basename(pathname) for pathname in props["spring_framework"]["files"]]) + "\n"
62-
"There are required:\n " +
63-
"\n ".join([x + "*.RELEASE.jar" for x in required_fname_prefixes])
64-
)
53+
if fname.endswith(".RELEASE.jar"):
54+
props["spring_framework"]["paths"].append(os.path.join(directory, fname))
6555
else:
6656
props["spring_framework"]["error"] = "Cannot access Spring Framework's directory " + directory
6757
return props
@@ -169,9 +159,10 @@ def evaluate(cmdline, common_libraries):
169159
classes_jar_pathname = os.path.abspath(os.path.join(cmdline.results_dir, "program.json"))
170160
prof["collect_java_binaries"] = mkbench.collect_java_binaries(
171161
cmdline.input_path,
172-
cmdline.libraries + (common_libraries["diffblue_models_library"]["files"] if cmdline.use_models_library else [])
173-
+ (common_libraries["apache_tomcat"]["files"] if cmdline.use_apache_tomcat else [])
174-
+ (common_libraries["spring_framework"]["files"] if cmdline.use_spring_framework else []),
162+
cmdline.libraries
163+
+ (common_libraries["diffblue_models_library"]["paths"] if cmdline.use_models_library else [])
164+
+ (common_libraries["apache_tomcat"]["paths"] if cmdline.use_apache_tomcat else [])
165+
+ (common_libraries["spring_framework"]["paths"] if cmdline.use_spring_framework else []),
175166
cmdline.entry_point,
176167
cmdline.temp_dir,
177168
classes_jar_pathname,

0 commit comments

Comments
 (0)