Fraunhofer-AISEC / cpg

A library to extract Code Property Graphs from C/C++, Java, Go, Python, Ruby and every other language through LLVM-IR.
https://fraunhofer-aisec.github.io/cpg/
Apache License 2.0
248 stars 60 forks source link

Adding EOG edge building pass as subvariant of the current eog pass t… #71

Closed konradweiss closed 4 years ago

konradweiss commented 4 years ago

…hat connects some language structures differently. Structures like if, for, switch, synchronized have an expression that needs to be evaluated first and these are now connected to the root node of the expression before the eog connects the 'body' this allows to parse the expression and then deduce its meaning from the following node that is the root node and thus gives information on the semantic of the overal language structue.

oxisto commented 4 years ago

What is the reasoning behind having two passes now?

JulianSchuette commented 4 years ago

What is the reasoning behind having two passes now?

I'll test it against #64 and if it's correct and does not fail the existing analyses, we'll migrate to only this new pass.

JulianSchuette commented 4 years ago

Looks good to me, at least for IfStatement. I would propose to replace the current EOG pass with this variant, so it will also become part of defaultPasses().

oxisto commented 4 years ago

Yes, please combine it into one pass @konradweiss

JulianSchuette commented 4 years ago

Ah, well. The graph itself looks good, but the tests are still NOK. This needs to be fixed first:

DemoTests.testHierarchy():

java.lang.StackOverflowError
    at java.base/java.lang.Class.getSimpleName(Class.java:1550)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.pushToEOG(EvaluationOrderGraphPass.java:786)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:594)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:39)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:574)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:40)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:574)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:40)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:574)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:40)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:574)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:40)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:574)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:40)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:574)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:40)
    at de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass.createEOG(EvaluationOrderGraphPass.java:574)
    at de.fraunhofer.aisec.cpg.passes.BranchSemanticEOGPass.handleConditionalExpression(BranchSemanticEOGPass.java:40)
...

Also, both test cases in JavaVsCppTest need to be adapted and I am unsure if this order is actually correct:

0 Literal
1 VariableDeclaration
2 DeclarationStatement
3 DeclaredReferenceExpression
4 Literal
5 BinaryOperator
6 IfStatement
7 DeclaredReferenceExpression
8 DeclaredReferenceExpression
9 DeclaredReferenceExpression
10 CallExpression
11 BinaryOperator
12 ReturnStatement
13 CompoundStatement
sonarcloud[bot] commented 4 years ago

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 29 Code Smells

72.9% 72.9% Coverage
15.7% 15.7% Duplication