joern icon indicating copy to clipboard operation
joern copied to clipboard

c2cpg: method fullname contains absolute filepath of the source directory

Open mpollmeier opened this issue 2 years ago • 2 comments

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

mpollmeier avatar Jun 23 '22 08:06 mpollmeier

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.

max-leuthaeuser avatar Jun 23 '22 08:06 max-leuthaeuser

depends on some internals which we're discussing on slack including @fabsx00

mpollmeier avatar Jun 23 '22 09:06 mpollmeier

Done with: https://github.com/joernio/joern/pull/2090 and follow-ups.

max-leuthaeuser avatar Dec 22 '22 11:12 max-leuthaeuser