diff --git a/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDsl.kt b/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDsl.kt index 64346e6b1..07e1fdbbd 100644 --- a/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDsl.kt +++ b/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDsl.kt @@ -195,7 +195,6 @@ infix fun Any.cpgFlowsTo(that: Collection): Result = is Array<*> -> this.anyResult { it?.cpgFlowsTo(that) } is Node -> that.any { dataFlow(this, it).value } is ParameterGroup -> this.parameters.allResult { it?.cpgFlowsTo(that) } - is Length -> checkLength(that) else -> this in that.map { (it as Expression).evaluate() } } ) @@ -222,19 +221,6 @@ private fun Any.checkRange(that: Collection): Boolean { } } -private fun Length.checkLength(that: Collection): Result { - return Result.convert( - that.all { - val size = sizeof(it).value - if (size == -1) { - // Handle case where size could not be determined -> OPEN Finding - return OPEN - } - size in this.value - } - ) -} - context(CokoBackend) // TODO: better description // TODO: in mark there is "..." to symbolize that the last arguments don't matter diff --git a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDslTest.kt b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDslTest.kt index 10871daa1..5aca136c1 100644 --- a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDslTest.kt +++ b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/dsl/ImplementationDslTest.kt @@ -81,78 +81,9 @@ class ImplementationDslTest { } } - @Disabled("sizeof in CPG currently does not support InitListExpression as initializer") - @Test - fun `test Array Length`() { - val opX: MutableList = mutableListOf() - for (i in 0..3) { - opX += op { - "Foo.fun" { - signature( - Length(i..i) - ) - } - } - } - - val results = arrayOf(1, 0, 1, 2) - for (i in 0..3) { - with(lengthBackend) { - val nodes = opX[i].cpgGetNodes() - val validNodes = nodes.filter { it.value == Result.VALID } - assertEquals( - results[i], - validNodes.size, - "cpgGetNodes returned ${validNodes.size} node(s) instead of ${results[i]} nodes " + - "for the Op: ${opX[i]}." - ) - assertEquals( - 1, - nodes.filter { it.value == Result.OPEN }.size, - "cpgGetNodes did not return exactly one OPEN result as expected." - ) - } - } - } - - @Disabled("sizeof in CPG currently does not support MemberCallExpression as Initializer") - @Test - fun `test List Length`() { - val opX: MutableList = mutableListOf() - for (i in 0..3) { - opX += op { - "Foo.bar" { - signature( - Length(i..i) - ) - } - } - } - - val results = arrayOf(1, 0, 1, 2) - for (i in 0..3) { - with(lengthBackend) { - val nodes = opX[i].cpgGetNodes() - val validNodes = nodes.filter { it.value == Result.VALID } - assertEquals( - results[i], - validNodes.size, - "cpgGetNodes returned ${validNodes.size} node(s) instead of ${results[i]} nodes " + - "for the Op: ${opX[i]}." - ) - assertEquals( - 1, - nodes.filter { it.value == Result.OPEN }.size, - "cpgGetNodes did not return exactly one OPEN result as expected." - ) - } - } - } - companion object { lateinit var simpleBackend: CokoCpgBackend - lateinit var lengthBackend: CokoCpgBackend @BeforeAll @JvmStatic @@ -160,16 +91,12 @@ class ImplementationDslTest { val classLoader = ImplementationDslTest::class.java.classLoader val simpleFileResource = classLoader.getResource("ImplementationDslTest/SimpleJavaFile.java") - val lengthFileResource = classLoader.getResource("ImplementationDslTest/LengthJavaFile.java") assertNotNull(simpleFileResource) - assertNotNull(lengthFileResource) val simpleFile = simpleFileResource.toURI().toPath() - val lengthFile = lengthFileResource.toURI().toPath() simpleBackend = CokoCpgBackend(config = createCpgConfiguration(simpleFile)) - lengthBackend = CokoCpgBackend(config = createCpgConfiguration(lengthFile)) } } } diff --git a/codyze-backends/cpg/src/test/resources/ImplementationDslTest/LengthJavaFile.java b/codyze-backends/cpg/src/test/resources/ImplementationDslTest/LengthJavaFile.java deleted file mode 100644 index 53b1ef7f4..000000000 --- a/codyze-backends/cpg/src/test/resources/ImplementationDslTest/LengthJavaFile.java +++ /dev/null @@ -1,42 +0,0 @@ -import java.util.List; -import java.lang.String; - -public class Length { - - public void one(int[] e) { - Foo f = new Foo(); - - int[] a = {1, 2, 3}; - int[] b = { }; - String[] c = {"a", "b", "c"}; - String[] d = {"ab", "c"}; - - f.fun(a); - f.fun(b); - f.fun(c); - f.fun(d); - f.fun(e); - } - - public void two(List e) { - Foo f = new Foo(); - - List a = List.of(1, 2, 3); - List b = List.of(); - List c = List.of("a", "b", "c"); - List c = List.of("ab", "c"); - - f.bar(a); - f.bar(b); - f.bar(c); - f.bar(d); - f.bar(e); - } -} - - -public class Foo { - public void fun(int[] a) {} - - public void bar(List l) {} -} diff --git a/codyze-specification-languages/coko/coko-core/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/core/dsl/Types.kt b/codyze-specification-languages/coko/coko-core/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/core/dsl/Types.kt index 28c097db4..c0363f54e 100644 --- a/codyze-specification-languages/coko/coko-core/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/core/dsl/Types.kt +++ b/codyze-specification-languages/coko/coko-core/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/core/dsl/Types.kt @@ -29,7 +29,4 @@ data class Type(val fqn: String) data class ParamWithType(val param: Any, val type: Type) -/** Marks that we want to check the length of the argument, not the contents */ -data class Length(val value: IntRange) - infix fun Any.withType(fqn: String) = ParamWithType(this, Type(fqn))