diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt index d48ca03a769..7bd1c16dcc0 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt @@ -196,6 +196,12 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : TranslationUni state.push(currentNode, it) } } else if ((currentNode as? Reference)?.access == AccessValues.READWRITE) { + // We can only find a change if there's a state for the variable + doubleState.declarationsState[currentNode.refersTo]?.let { + // We only read the variable => Get previous write which have been collected in + // the other steps + state.push(currentNode, it) + } // We read and write to the variable => Update the declarationState accordingly because // there was probably some other kind of DFG edge into the reference doubleState.declarationsState[currentNode.refersTo] = diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt index fa4f4c6ec91..d4983c5dd63 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/EvaluationOrderGraphPass.kt @@ -513,12 +513,12 @@ open class EvaluationOrderGraphPass(ctx: TranslationContext) : TranslationUnitPa createEOG(declaration) } - // Handle left hand side(s) first - node.lhs.forEach { createEOG(it) } - - // Then the right side(s) + // Handle the right side(s) first node.rhs.forEach { createEOG(it) } + // Then the left hand side(s) + node.lhs.forEach { createEOG(it) } + pushToEOG(node) } diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt index adf48e0eb29..09bba9152f7 100644 --- a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt @@ -360,15 +360,23 @@ class GraphExamples { ifStmt { condition { ref("b") gt literal(0, t("int")) } thenStmt { - ref("d") assign ref("a") * literal(2, t("int")) + ref("d") assign + { + ref("a") * literal(2, t("int")) + } ref("a") assign - ref("a") + ref("d") * literal(2, t("int")) + { + ref("a") + + ref("d") * literal(2, t("int")) + } } elseIf { condition { ref("b") lt literal(-2, t("int")) } thenStmt { ref("a") assign - ref("a") - literal(10, t("int")) + { + ref("a") - literal(10, t("int")) + } } } }