From dd465e739bbb4e39c0f2bc51bc43f33f625f2ea9 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Wed, 3 Aug 2022 10:41:44 +0200 Subject: [PATCH] Code review suggestion --- .../dataflow/internal/DataFlowDispatch.qll | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll index c0882219058..76c018df03d 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll @@ -4,7 +4,6 @@ private import dotnet private import DataFlowImplCommon as DataFlowImplCommon private import DataFlowPublic private import DataFlowPrivate -private import semmle.code.csharp.controlflow.internal.Splitting private import FlowSummaryImpl as FlowSummaryImpl private import semmle.code.csharp.dataflow.FlowSummary as FlowSummary private import semmle.code.csharp.dataflow.ExternalFlow @@ -22,7 +21,13 @@ private import semmle.code.csharp.frameworks.system.collections.Generic */ DotNet::Callable getCallableForDataFlow(DotNet::Callable c) { exists(DotNet::Callable unboundDecl | unboundDecl = c.getUnboundDeclaration() | - result.hasBody() and + ( + result.hasBody() + or + // take synthesized bodies into account, e.g. implicit constructors + // with field initializer assignments + result = any(ControlFlow::Nodes::ElementNode n).getEnclosingCallable() + ) and if unboundDecl.getFile().fromSource() then // C# callable with C# implementation in the database @@ -40,16 +45,6 @@ DotNet::Callable getCallableForDataFlow(DotNet::Callable c) { // C# callable without C# implementation in the database unboundDecl.matchesHandle(result.(CIL::Callable)) ) - or - result = c.getUnboundDeclaration() and - isDefaultConstructorWithMemberInit(result) -} - -private predicate isDefaultConstructorWithMemberInit(InstanceConstructor c) { - c.isUnboundDeclaration() and - c.getFile().fromSource() and - not c.hasBody() and - InitializerSplitting::constructorInitializes(c, _) } /**