cprover
java_class_loader_limit.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: limit class path loading
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
13 
14 #include <json/json_parser.h>
15 
19  const std::string &java_cp_include_files)
20 {
21  if(java_cp_include_files.empty())
22  throw "class regexp cannot be empty, `get_language_options` not called?";
23 
24  // '@' signals file reading with list of class files to load
25  use_regex_match = java_cp_include_files[0] != '@';
26  if(use_regex_match)
27  regex_matcher=std::regex(java_cp_include_files);
28  else
29  {
30  assert(java_cp_include_files.length()>1);
31  jsont json_cp_config;
32  if(parse_json(
33  java_cp_include_files.substr(1),
35  json_cp_config))
36  throw "cannot read JSON input configuration for JAR loading";
37  if(!json_cp_config.is_object())
38  throw "the JSON file has a wrong format";
39  jsont include_files=json_cp_config["classFiles"];
40  if(!include_files.is_null() && !include_files.is_array())
41  throw "the JSON file has a wrong format";
42  for(const jsont &file_entry : include_files.array)
43  {
44  assert(file_entry.is_string());
45  set_matcher.insert(file_entry.value);
46  }
47  }
48 }
49 
52 bool java_class_loader_limitt::load_class_file(const std::string &file_name)
53 {
54  if(use_regex_match)
55  {
56  std::smatch string_matches;
57  return std::regex_match(file_name, string_matches, regex_matcher);
58  }
59  else
60  // load .class file only if it is in the match set
61  return set_matcher.find(file_name) != set_matcher.end();
62 }
Definition: json.h:23
bool parse_json(std::istream &in, const std::string &filename, message_handlert &message_handler, jsont &dest)
Definition: json_parser.cpp:16
std::set< std::string > set_matcher
bool is_null() const
Definition: json.h:69
message_handlert & get_message_handler()
Definition: message.h:153
bool is_string() const
Definition: json.h:39
bool is_array() const
Definition: json.h:54
std::string value
Definition: json.h:137
bool load_class_file(const std::string &class_file_name)
arrayt array
Definition: json.h:129
bool use_regex_match
Whether to use regex_matcher instead of set_matcher.
void setup_class_load_limit(const std::string &)
initializes class with either regex matcher or match set
limit class path loading