Skip to content

Commit b6f1e0d

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#352 from diffblue/owen-jones-diffblue/add-entry-point-option
SEC-263: Add entry point option to security-scanner pipeline
2 parents 9999fca + 0ffc042 commit b6f1e0d

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

driver/mkbench.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _read_info_of_class_files(class_files, temp_dir, verbosity):
7171
return classes_info, java_class_info_call_duration
7272

7373

74-
def collect_java_binaries(app_path, list_of_classpaths, temp_dir, output_json, verbosity):
74+
def collect_java_binaries(app_path, list_of_classpaths, entry_point, temp_dir, output_json, verbosity):
7575
prof_start_time = time.time()
7676
prof = dict()
7777

@@ -135,7 +135,8 @@ def collect_java_binaries(app_path, list_of_classpaths, temp_dir, output_json, v
135135
with open(output_json, "w") as ofile:
136136
ofile.write(json.dumps({
137137
"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)])
138+
"classpath": sorted([p for p in list_of_classpaths + java_binaries.classpath_jar_files if os.path.exists(p)]),
139+
"entry-point": entry_point
139140
}, sort_keys=True, indent=4))
140141

141142
# Lastly, we complete and return statistics from this stage.

driver/run.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ def __parse_cmd_line():
8888
parser.add_argument("-L", "--libraries", nargs='+', default=[],
8989
help="A list of disk paths to libraries you want to include into class path. A path "
9090
"can either be a path-name of a JAR file, or a directory.")
91+
parser.add_argument("-E", "--entry-point", type=str,
92+
help="Allows you to specify a Java function which will be considered by the analyser as the "
93+
"entry point. Typically, a function of a class implementing javax.servlet.http.HttpServlet "
94+
"is a good candidate. When not specified, all functions of all classes are considered "
95+
"as potential entry points. The function must be fully classified (i.e. with the package "
96+
"and class included).")
9197
parser.add_argument("-R", "--results-dir", type=str,
9298
help="A directory into which all results from the analysis of the given Java web applicaton "
9399
"will be written.")
@@ -166,6 +172,7 @@ def evaluate(cmdline, common_libraries):
166172
cmdline.libraries + (common_libraries["diffblue_models_library"]["files"] if cmdline.use_models_library else [])
167173
+ (common_libraries["apache_tomcat"]["files"] if cmdline.use_apache_tomcat else [])
168174
+ (common_libraries["spring_framework"]["files"] if cmdline.use_spring_framework else []),
175+
cmdline.entry_point,
169176
cmdline.temp_dir,
170177
classes_jar_pathname,
171178
cmdline.verbosity
@@ -275,6 +282,10 @@ def __main():
275282
"a WAR file: " + os.path.abspath(cmdline.input_path))
276283
return
277284

285+
if cmdline.entry_point is not None and len(cmdline.entry_point) == 0:
286+
print("ERROR[--entry-point (-E)]: The entry point is empty. It must represent a fully classified function nane.")
287+
return
288+
278289
if cmdline.results_dir is None:
279290
print("ERROR[--results-dir (-R)]: The root directory where all results from the analysis should be saved into "
280291
"was not specified.")

src/driver/sec_driver_parse_options.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,16 @@ void sec_driver_parse_optionst::help()
448448
"\n"
449449
"Analyses:\n"
450450
"\n"
451-
" --security-scanner file_name perform taint analysis using configuration in given file\n"
451+
" --security-scanner file_name perform taint analysis using configuration "
452+
" in given JSON file\n"
452453
" --unreachable-instructions list dead code\n"
453454
" --intervals interval analysis\n"
454455
" --non-null non-null analysis\n"
455456
"\n"
456457
"Analysis options:\n"
457458
" --json file_name output results in JSON format to given file\n"
458459
" --xml file_name output results in XML format to given file\n"
460+
" --function set main function name\n"
459461
"\n"
460462
"C/C++ frontend options:\n"
461463
" -I path set include path (C/C++)\n"

src/taint-analysis/taint_config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,8 @@ void taint_build_cmdline_from_config(
246246
classpaths.push_back(classpath.value);
247247
static_cast<cmdline_updatert*>(&cmdline)->add_to_classpaths(classpaths);
248248
}
249+
attr_it = cfg.object.find("entry-point");
250+
if (attr_it != cfg.object.cend())
251+
cmdline.set("function", attr_it->second.value);
249252
cmdline.set("lazy-methods");
250253
}

0 commit comments

Comments
 (0)