bugfinder.processing.neo4j.annot

Module for annotating neo4J graphs

class bugfinder.processing.neo4j.annot.Neo4JAnnotations(dataset, deprecation_warning=None)

Bases: Neo4J3Processing

Neo4J annotation class

COMMANDS = ['MATCH (n) SET n:GenericNode;', 'CREATE INDEX ON :GenericNode(type);', 'CREATE INDEX ON :GenericNode(code);', 'CREATE INDEX ON :GenericNode(filepath);', "\n            MATCH (root1:GenericNode)-[:FLOWS_TO|REACHES|CONTROLS]->()\n            WHERE root1.type IN [\n                'Condition', 'ForInit', 'IncDecOp', 'PostIncDecOperationExpression',\n                'ExpressionStatement', 'IdentifierDeclStatement', 'CFGEntryNode',\n                'BreakStatement', 'Parameter', 'ReturnStatement', 'Label',\n                'GotoStatement', 'Statement', 'UnaryExpression'\n            ]\n            SET root1:UpstreamNode;\n        ", "\n            MATCH ()-[:FLOWS_TO|REACHES|CONTROLS]->(root2:GenericNode)\n            WHERE root2.type IN [\n                'CFGExitNode', 'IncDecOp', 'Condition', 'PostIncDecOperationExpression',\n                'ExpressionStatement', 'ForInit', 'IdentifierDeclStatement',\n                'BreakStatement', 'Parameter', 'ReturnStatement', 'Label',\n                'GotoStatement', 'Statement', 'UnaryExpression'\n            ]\n            SET root2:DownstreamNode;\n        ", '\n            MATCH (n {type:"Function"})\n            WHERE EXISTS(n.name)\n            SET n.code=n.name;\n        ', '\n            MATCH (n {type:"File"})\n            WHERE EXISTS(n.filepath)\n            SET n.code=n.filepath;\n        ', '\n            MATCH (node)\n            WHERE EXISTS(node.functionId)\n            SET node.functionId=toString(node.functionId);\n        ', "\n            MATCH (file:GenericNode {type:'File'})\n            WITH split(file.code,'/')[2..4] as tc, COLLECT(distinct file) AS files\n            MERGE (testcase:GenericNode { type:'Testcase', label:tc[0], name:tc[1]})\n            WITH testcase, files\n            UNWIND files as file\n            WITH testcase, file\n            MERGE (testcase)<-[r:IS_FILE_OF]-(file)\n        ", '\n            MATCH (n1:DownstreamNode)-[r:REACHES {var:"NULL"}]->(n2:DownstreamNode)\n            DELETE r\n        ', '\n            MATCH (:GenericNode {type:"Symbol", code:"NULL"})<-[d:DEF]-()\n            DELETE d\n        ', '\n            MATCH (f:GenericNode {type:"File"})\n            SET f.basename=split(f.code,\'/\')[-1]\n        ', '\n            MATCH (n1:GenericNode)\n            WHERE exists(n1.location)\n            SET n1.lineno=toInteger(split(n1.location,":")[0])\n        ', '\n            MATCH (:GenericNode {type:"CFGExitNode"})<-[r:REACHES]-()\n            DELETE r\n        ', '\n            MATCH (n:GenericNode {type:"IdentifierDeclStatement"})\n            WHERE n.code =~ \'.* \\\\[ [0-9]* \\\\].*\'\n            WITH\n                n,\n                split(split(n.code,\' [\')[0],\' \')[-1] as var,\n                toInteger(split(split(n.code,\'[ \')[1],\' ]\')[0]) as sz\n            MATCH p=(n)-[:REACHES* {var:var}]->()\n            UNWIND relationships(p) as r\n            SET r.size=sz\n        ', '\n            MATCH (xpr:DownstreamNode)-[:IS_AST_PARENT*]->(cal:GenericNode {type:"CallExpression"})-[:IS_AST_PARENT]->(alc:GenericNode {type:"Callee"})\n            WHERE xpr.type in ["IdentifierDeclStatement","ExpressionStatement"]\n              AND alc.code in ["malloc","ALLOCA","realloc","calloc"]\n            WITH xpr, cal, case alc.code when "realloc" then "1" else "0" end as argnum\n            MATCH (cal)-[:IS_AST_PARENT]->(:GenericNode {type:"ArgumentList"})-[:IS_AST_PARENT]->(arg:GenericNode {type:"Argument",childNum:argnum})\n            WITH xpr, arg\n            MATCH (arg)-[:IS_AST_PARENT*]->(operand:GenericNode)\n            WHERE substring(operand.type,0,6)<>"Sizeof" and not (operand)-[:IS_AST_PARENT]->()\n            WITH xpr, collect(operand) as oplist\n            WHERE size(oplist)=1 and oplist[0].type="PrimaryExpression"\n            MATCH (xpr)-[:DEF]->(sym:GenericNode {type:"Symbol"})\n            MATCH dfp=(xpr)-[:REACHES* {var:sym.code}]->()\n            UNWIND relationships(dfp) as dfr\n            SET dfr.size=tointeger(oplist[0].code)\n        ', '\n            MATCH (axpr:GenericNode {type:"AssignmentExpression"})<-[:IS_AST_PARENT*]-(expr:DownstreamNode)\n            WHERE expr.type in ["ExpressionStatement","IdentifierDeclStatement","ForInit"]\n            MATCH (axpr)-[:USE]->(ssym:GenericNode {type:"Symbol"})\n            MATCH (expr)<-[src:REACHES {var:ssym.code}]-() where exists(src.size)\n            MATCH (axpr)-[:DEF]->(dsym:GenericNode {type:"Symbol"})\n            MATCH p=(expr)-[:REACHES* {var:dsym.code}]->()\n            UNWIND relationships(p) as dst\n            SET dst.size=src.size\n            SET dst.src=src.var\n        ', '\n            MATCH (expr:DownstreamNode)-[:IS_AST_PARENT*]->(asgn:GenericNode {type:"AssignmentExpression"})-[:IS_AST_PARENT]->(aidx:GenericNode {type:"ArrayIndexing",childNum:"0"})-[:IS_AST_PARENT]->(idfr:GenericNode {type:"Identifier",childNum:"1"})\n            MATCH (expr)-[rd1:DEF]->(sym:GenericNode {type:"Symbol",code:"* "+idfr.code})<-[rd2:DEF]-(asgn)\n            DELETE rd1, rd2\n        ', '\n            MATCH (decl:GenericNode {type:"IdentifierDeclStatement"})-[rdef:DEF]->(sym:GenericNode {type:"Symbol"})\n            WHERE left(sym.code,2)<>"& "\n              AND not (decl)-[:IS_AST_PARENT]->(:GenericNode {type:"IdentifierDecl"})-[:DEF]->(sym)\n            DELETE rdef\n        ']
configure_container()

Setup container variables.

send_commands()

Send commands to the container