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

Various fixes for declarations #179

Closed oxisto closed 3 years ago

oxisto commented 3 years ago

In this process, I have decided to merge the DeclarationListHandler into the DeclarationHandler. Since an handler can only return Node types or List<Node> types, I have introduced the DeclarationSequence node. This node should not end up in the final graph and will be "flattened" during CPG transformation.

Closes #178

oxisto commented 3 years ago

Ok, I have no idea, why the CFG tests fail. They also only fail sometimes it seems :(

oxisto commented 3 years ago

The test design here does not make sense in my opinion. It tries to get all AST in getByLineNr using SubgraphWalker.flattenAST, including also declarations, which cannot even receive CFG edges. If then someone is a declaration on the same line as a statement and parsed before the statement it returns the declaration in this line.

oxisto commented 3 years ago

The main problem is, that I cannot really test codyze because for some reason, this branch leads to https://github.com/Fraunhofer-AISEC/codyze/issues/37.

All changes are documented above and they should not introduce anything that "breaks", if they do, then it was always broken and probably worked around in codyze. Seems we have a little bit of a chicken-and-egg problem here.

oxisto commented 3 years ago

So it looks like that it all started with https://github.com/Fraunhofer-AISEC/cpg/pull/164 which somehow causes the OGM wrapper within codyze to malfunction and do all kind of crazy things such as not recognising relationships or not finding property values and so on. It seems to have an issue with the annotations field within Node, which looks perfectly fine to me.

https://github.com/Fraunhofer-AISEC/cpg/blob/6af6499ae50cfc1ea8b51631a0d17bcf146b415a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java#L118-L119

oxisto commented 3 years ago

Two field relationships were incorrectly defines as incoming, although they should be outgoing. Together with https://github.com/Fraunhofer-AISEC/codyze/pull/41 this should be enough to successfully run all tests on codyze.

sonarcloud[bot] commented 3 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 6 Code Smells

84.4% 84.4% Coverage
0.0% 0.0% Duplication