Skip to content

Commit 8e36d2f

Browse files
authored
Merge pull request diffblue#228 from diffblue/feature/dump_of_goto_stats_of_slicing_tasks
SEC-41 : Adding a use of statistics of GOTO program in security-analyser.
2 parents 464e5ad + 5f35a0e commit 8e36d2f

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/taint-slicer/slicing_tasks_builder.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <goto-programs/write_goto_binary.h>
1515
#include <goto-programs/remove_returns.h>
1616
#include <goto-programs/goto_convert_functions.h>
17+
#include <goto-programs/goto_statistics.h>
1718
#include <java_bytecode/java_entry_point.h>
1819
#include <util/config.h>
1920
#include <util/cprover_prefix.h>
@@ -324,7 +325,55 @@ std::pair<taint_slicing_taskt,std::string> build_slicing_task(
324325
if(fail)
325326
fail_message="Not available.";
326327
else
327-
return {{props.get_root(),sink_locations,pathname},""};
328+
{
329+
// Before return we compute and same basic statistics of the saved
330+
// GOTO program (i.e. the slicing task). These statistics will later
331+
// be used by the Python driver script to compare them with similar
332+
// statistics from the full slicer (implemented in goto-instrument)
333+
// in order to get the efficiency of the slicing.
334+
335+
const std::string out_json_file_pathname=
336+
fileutl_remove_extension(pathname) + ".stats.json";
337+
338+
// We start with safety check related to the file to be written.
339+
bool can_write_stats=true;
340+
if(fileutl_is_directory(out_json_file_pathname))
341+
{
342+
logger->error()
343+
<< "The path-name '"
344+
<< out_json_file_pathname
345+
<< "' for the statistics JSON output is actually an existing "
346+
<< "directory."
347+
<< messaget::eom;
348+
can_write_stats=false;
349+
}
350+
if(fileutl_parse_extension_in_pathname(out_json_file_pathname)!=".json")
351+
{
352+
logger->error()
353+
<< "The file of the path-name '" << out_json_file_pathname
354+
<< "' for the statistics JSON output does not have '.json' extension."
355+
<< messaget::eom;
356+
can_write_stats=false;
357+
}
358+
if(can_write_stats)
359+
{
360+
// And let's compute and save the statistics.
361+
goto_statisticst stats;
362+
stats.extend(goto_model);
363+
std::ofstream ofile(out_json_file_pathname);
364+
if(!ofile)
365+
{
366+
logger->error()
367+
<< "Failed to open the JSON file '" << out_json_file_pathname
368+
<< "' for writing. The statistic of the GOTO program won't be "
369+
<< "available."
370+
<< messaget::eom;
371+
}
372+
else
373+
ofile << to_json(stats);
374+
}
375+
return {{props.get_root(), sink_locations, pathname}, ""};
376+
}
328377
}
329378
catch(const std::exception &e)
330379
{

0 commit comments

Comments
 (0)