Skip to content

Commit ad20aeb

Browse files
committed
Propagation of library JAR files to classpath
1 parent 2f581e2 commit ad20aeb

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

driver/mkbench.py

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

7272

73-
def collect_java_binaries(app_binary_dirs, temp_dir, output_json, verbosity):
73+
def collect_java_binaries(app_binary_dirs, list_of_classpaths, temp_dir, output_json, verbosity):
7474
prof_start_time = time.time()
7575
prof = dict()
7676

@@ -164,7 +164,10 @@ def collect_java_binaries(app_binary_dirs, temp_dir, output_json, verbosity):
164164
if not os.path.isdir(os.path.dirname(output_json)):
165165
os.makedirs(os.path.dirname(output_json))
166166
with open(output_json, "w") as ofile:
167-
ofile.write(json.dumps({"jar": java_binaries.jar_files}, sort_keys=True, indent=4))
167+
ofile.write(json.dumps({
168+
"jar": sorted(java_binaries.jar_files),
169+
"classpath": sorted([p for p in list_of_classpaths if os.path.exists(p)])
170+
}, sort_keys=True, indent=4))
168171

169172
# Lastly, we complete and return statistics from this stage.
170173
prof["num_jars_final"] = len(java_binaries.jar_files)

driver/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def __parse_cmd_line():
2828
help="The install directory of the Java web application to be analysed. Under that "
2929
"directory (directly or indirectly) there should be all binaries files "
3030
"(WAR/JAR/CLASS files) of that wab application.")
31+
parser.add_argument("-L", "--libraries", nargs='+', default=[],
32+
help="A list of disk paths to libraries you want to include into class path. A path "
33+
"can either be a path-name of a JAR file, or a directory.")
3134
parser.add_argument("-R", "--results-dir", type=str,
3235
help="A directory into which all results from the analysis of the given Java web applicaton "
3336
"will be written.")
@@ -104,6 +107,7 @@ def evaluate(cmdline):
104107
classes_jar_pathname = os.path.abspath(os.path.join(cmdline.results_dir, "program.json"))
105108
prof["collect_java_binaries"] = mkbench.collect_java_binaries(
106109
input_search_dirs,
110+
cmdline.libraries,
107111
cmdline.temp_dir,
108112
classes_jar_pathname,
109113
cmdline.verbosity

src/taint-analysis/taint_config.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,39 @@ bool taint_configt::load(message_handlert &handler)
191191
return false;
192192
}
193193

194+
struct cmdline_updatert : public cmdlinet
195+
{
196+
void add_to_classpaths(const std::vector<std::string> &classpaths)
197+
{
198+
PRECONDITION(!classpaths.empty());
199+
int idx=getoptnr("classpath");
200+
if(idx==-1)
201+
{
202+
options.push_back({});
203+
idx=int(options.size()-1UL);
204+
}
205+
if(options.at(idx).isset==false)
206+
{
207+
options.at(idx).isset=true;
208+
if(options.at(idx).values.empty())
209+
options.at(idx).values.push_back("");
210+
}
211+
std::string &dst_classpaths = options.at(idx).values.front();
212+
for(const auto &classpath : classpaths)
213+
{
214+
if(!dst_classpaths.empty())
215+
dst_classpaths+=
216+
#ifdef _WIN32
217+
';'
218+
#else
219+
':'
220+
#endif
221+
;
222+
dst_classpaths+=classpath;
223+
}
224+
}
225+
};
226+
194227
void taint_build_cmdline_from_config(
195228
const std::string &cfg_file_path,
196229
messaget * const logger,
@@ -213,5 +246,12 @@ void taint_build_cmdline_from_config(
213246
return;
214247
for(auto const &jar : cfg["jar"].array)
215248
cmdline.args.push_back(jar.value);
249+
if(!cfg["classpath"].array.empty())
250+
{
251+
std::vector<std::string> classpaths;
252+
for(auto const &classpath : cfg["classpath"].array)
253+
classpaths.push_back(classpath.value);
254+
static_cast<cmdline_updatert*>(&cmdline)->add_to_classpaths(classpaths);
255+
}
216256
cmdline.set("lazy-methods");
217257
}

0 commit comments

Comments
 (0)