joern
joern copied to clipboard
c2cpg: method fullname contains absolute filepath of the source directory
importCode.c("/home/mp/Projects/shiftleft/codescience/sptests/code/c/damn-vulnerable-c")
cpg.method.fullName(".*codescience.*").l
// 13 results, which mostly look like this:
Method(
id -> 51351L,
astParentFullName -> "/home/mp/Projects/shiftleft/codescience/sptests/code/c/damn-vulnerable-c:<includes>:<global>",
astParentType -> "NAMESPACE_BLOCK",
code -> "<global>",
columnNumber -> None,
columnNumberEnd -> None,
filename -> "/home/mp/Projects/shiftleft/codescience/sptests/code/c/damn-vulnerable-c:<includes>",
fullName -> "/home/mp/Projects/shiftleft/codescience/sptests/code/c/damn-vulnerable-c:<includes>:<global>",
hash -> None,
isExternal -> false,
lineNumber -> Some(value = 1),
lineNumberEnd -> None,
name -> "<global>",
order -> 1,
signature -> ""
)
I'd expect something like
-
astParentFullName=<includes>:<global>
-
fullName=<includes>:<global>
- not sure about
filename
tbh...
I had a look in the frontend code: the fullname is set in https://github.com/joernio/joern/blob/master/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreator.scala#L86, and it takes it from the GlobalNamespaceBlockFullName, which is set at https://github.com/joernio/joern/blob/master/joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/AstCreatorBase.scala#L29
Easy fix would look like the one used in jssrc2cpg: https://github.com/joernio/joern/blob/master/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/astcreation/AstCreator.scala#L61
Requires adaptions in joern/sptests.
depends on some internals which we're discussing on slack including @fabsx00
Done with: https://github.com/joernio/joern/pull/2090 and follow-ups.