From 83029e495e7c0ced3a367842ffeab3c4b91bfba7 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Tue, 2 Jan 2024 12:33:15 +0100 Subject: [PATCH] Asserted data flow in field --- .../cpg/frontends/JVMLanguageFrontendTest.kt | 16 ++++++++++++++++ .../class/fields/mypackge/Fields.class | Bin 373 -> 383 bytes .../resources/class/fields/mypackge/Fields.java | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cpg-language-jvm/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/JVMLanguageFrontendTest.kt b/cpg-language-jvm/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/JVMLanguageFrontendTest.kt index c2fca921131..5fd3a3623f1 100644 --- a/cpg-language-jvm/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/JVMLanguageFrontendTest.kt +++ b/cpg-language-jvm/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/JVMLanguageFrontendTest.kt @@ -28,9 +28,12 @@ package de.fraunhofer.aisec.cpg.frontends import de.fraunhofer.aisec.cpg.TestUtils import de.fraunhofer.aisec.cpg.TestUtils.assertInvokes import de.fraunhofer.aisec.cpg.assertFullName +import de.fraunhofer.aisec.cpg.assertLiteralValue import de.fraunhofer.aisec.cpg.assertLocalName import de.fraunhofer.aisec.cpg.graph.* +import de.fraunhofer.aisec.cpg.graph.declarations.FieldDeclaration import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression +import de.fraunhofer.aisec.cpg.graph.statements.expressions.Literal import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberCallExpression import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberExpression import de.fraunhofer.aisec.cpg.passes.EdgeCachePass @@ -196,6 +199,19 @@ class JVMLanguageFrontendTest { "${it.name} should not be resolved to an inferred node" ) } + + val setACall = tu.calls["setA"] + assertNotNull(setACall) + + val lit10 = setACall.arguments.firstOrNull() + assertIs>(lit10) + assertLiteralValue(10, lit10) + + // We should be able to follow the literal back to it's write to the field + val result = + lit10.followNextDFGEdgesUntilHit { it is FieldDeclaration && it.name.localName == "a" } + assertNotNull(result) + assertEquals(1, result.fulfilled.size) } @Disabled diff --git a/cpg-language-jvm/src/test/resources/class/fields/mypackge/Fields.class b/cpg-language-jvm/src/test/resources/class/fields/mypackge/Fields.class index 5ed5f1649d8adf9a1d1f7b1884e04128e3ef1bd7..3ef2237bee78f8ea028fb60d0f4dc35522da444f 100644 GIT binary patch delta 235 zcmey$^q-0A)W2Q(7#J8F86+lhWf^iYa4-n+FbFXSGcvFgr5LHd<|`k8<R|fJx c_OWXTD06LN5J1-<08}XmR3Qdb!^9vC02I|6CjbBd delta 128 zcmey*^p%P0)W2Q(7#J8F8N?=XWlijn=3yyLEpcRIVA1f@44b&rf>B`NJ$XjKiT~so z1t!ZeihBtHRdX>g0ZASPRt8=mi=TmwfssJ~D54DHF#>6JEdj2r4D1_$OhyKT1_7W# NL7<2TP@IWD6aWc%6AS