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
270 stars 61 forks source link

TranslationException: translation context not available #1617

Closed peckto closed 1 month ago

peckto commented 1 month ago

Stack trace

java.util.concurrent.ExecutionException: de.fraunhofer.aisec.cpg.frontends.TranslationException: Could not create type: translation context not available
    at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
    at de.fraunhofer.aisec.cpg_vis_neo4j.Application.call(Application.kt:610)
    at de.fraunhofer.aisec.cpg_vis_neo4j.Application.call(Application.kt:88)
    at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
    at picocli.CommandLine.access$1500(CommandLine.java:148)
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
    at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
    at picocli.CommandLine.execute(CommandLine.java:2170)
    at de.fraunhofer.aisec.cpg_vis_neo4j.ApplicationKt.main(Application.kt:651)
Caused by: de.fraunhofer.aisec.cpg.frontends.TranslationException: Could not create type: translation context not available
    at de.fraunhofer.aisec.cpg.graph.TypeBuilderKt.objectType(TypeBuilder.kt:112)
    at de.fraunhofer.aisec.cpg.graph.TypeBuilderKt.objectType$default(TypeBuilder.kt:96)
    at de.fraunhofer.aisec.cpg.passes.CXXExtraPass.convertOperators(CXXExtraPass.kt:119)
    at de.fraunhofer.aisec.cpg.passes.CXXExtraPass.accept$lambda$0(CXXExtraPass.kt:61)
    at de.fraunhofer.aisec.cpg.helpers.SubgraphWalker$ScopedWalker.handleNode(SubgraphWalker.kt:400)
    at de.fraunhofer.aisec.cpg.helpers.SubgraphWalker$ScopedWalker.iterate$lambda$3$lambda$2(SubgraphWalker.kt:383)
    at de.fraunhofer.aisec.cpg.helpers.SubgraphWalker$IterativeGraphWalker.iterate(SubgraphWalker.kt:283)
    at de.fraunhofer.aisec.cpg.helpers.SubgraphWalker$ScopedWalker.iterate(SubgraphWalker.kt:387)
    at de.fraunhofer.aisec.cpg.passes.CXXExtraPass.accept(CXXExtraPass.kt:67)
    at de.fraunhofer.aisec.cpg.passes.CXXExtraPass.accept(CXXExtraPass.kt:47)
    at de.fraunhofer.aisec.cpg.passes.PassKt.executePass(Pass.kt:391)
    at de.fraunhofer.aisec.cpg.TranslationManager.analyzeNonAsync(TranslationManager.kt:102)
    at de.fraunhofer.aisec.cpg.TranslationManager.analyze$lambda$0(TranslationManager.kt:70)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Unexpected behavior

The cpg crashes during CXXExtraPass.

Code of interest

//typedef unsigned char u_int8_t;

int foo(const u_int8_t *p)
{
    u_int8_t *valp;
    *valp = (u_int8_t)*p;
    return 0;
}

Extensions to the library, e.g. added or changed LanguageFrontends or Passes

None

Changes to the configuration

$ cpg-neo4j poc.c

Description

The Language Node does not have a ctx (null) but is expected by LanguageProvider.objectType.

Where does the Language Node come from? Is it expected to have a context?

oxisto commented 1 month ago

It is magic and appears out of nowhere sometimes :D And yes it should have a context. I will have a look.