#include <Metric.h>
Definition at line 131 of file Metric.h.
Public Member Functions | |
NumberResources () | |
NumberResources (const std::list< std::string > &sinks, const Ast *_ast=0) | |
virtual | ~NumberResources () |
virtual MetricResult | operator() (const tree< AstNode > &, const MapClasses *classes=0, const MapVariables *vars=0, const MapFunctions *func=0, const MapAssignments *assigns=0, const MapVarEquivalent *equiv=0) |
Data Fields | |
std::list< std::string > | taintedinput |
const Ast * | ast |
NumberResources::NumberResources | ( | const std::list< std::string > & | sinks, | |
const Ast * | _ast = 0 | |||
) | [inline] |
Definition at line 138 of file Metric.h.
References ast, and taintedinput.
00138 { 00139 taintedinput = sinks; 00140 ast = _ast; 00141 }
virtual NumberResources::~NumberResources | ( | ) | [inline, virtual] |
MetricResult NumberResources::operator() | ( | const tree< AstNode > & | tr, | |
const MapClasses * | classes = 0 , |
|||
const MapVariables * | vars = 0 , |
|||
const MapFunctions * | func = 0 , |
|||
const MapAssignments * | assigns = 0 , |
|||
const MapVarEquivalent * | equiv = 0 | |||
) | [virtual] |
Implements Metric.
Definition at line 111 of file Metric.cpp.
References ast, tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::end(), Ast::getBoxedFunctions(), MetricResult::main, utils::start_with(), and taintedinput.
00113 { 00114 MetricResult result; 00115 NumericResult num; 00116 unsigned n = 0; 00117 // Get the outputs functions in the tree-functions. if there is one, just add the function into the list of sensitive 00118 std::map<std::string, BoxedFunction> boxedFunctions = ast->getBoxedFunctions(); 00119 for (std::map<std::string, BoxedFunction>::iterator iter=boxedFunctions.begin();iter!=boxedFunctions.end();++iter) 00120 { 00121 // iterate through the boxedFunctions output 00122 bool add = false; 00123 for(MapFunctions::iterator jter=iter->second.input.begin();jter!=iter->second.input.end();++jter) { 00124 if (find(taintedinput.begin(), taintedinput.end(), jter->first) != taintedinput.end()) { 00125 add = true; 00126 break; 00127 } 00128 } 00129 if (add) { 00130 if (find(taintedinput.begin(), taintedinput.end(), iter->first) == taintedinput.end()) 00131 taintedinput.push_back(iter->first); 00132 } 00133 } 00134 // return the number of functions in the current source code 00135 for (tree<AstNode>::iterator iter = tr.begin(); iter != tr.end(); ++iter) { 00136 string t = iter->getType(); 00137 if (t == "unticked_function_declaration_statement") { 00138 iter = tr.end(iter); 00139 } 00140 else if (t == "function_call") { 00141 tree<AstNode>::iterator son = tr.begin(iter); 00142 if (son->getType() == "T_STRING") { 00143 tree<AstNode>::iterator textable = tr.begin(son); 00144 if (textable->getType() == "text" && find(taintedinput.begin(), taintedinput.end(), textable->getValue()) != taintedinput.end()) { 00145 n++; 00146 } 00147 } 00148 } 00149 else if (t == "unticked_statement" || t == "expr_without_variable") { 00150 tree<AstNode>::iterator son = tr.begin(iter); 00151 if (utils::start_with(son->getType(), "T_")) { 00152 tree<AstNode>::iterator textable = tr.begin(son); 00153 if (textable->getType() == "text" && find(taintedinput.begin(), taintedinput.end(), textable->getValue()) != taintedinput.end()) { 00154 n++; 00155 } 00156 } 00157 } 00158 } 00159 00160 // add the boxed source 00161 00162 00163 00164 00165 00166 num = n; 00167 result.main = num; 00168 return result; 00169 }
std::list<std::string> NumberResources::taintedinput |
const Ast* NumberResources::ast |