From 73c6d89bcde00b5c9773bec9de7a4ea3e1ebff30 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Mon, 11 May 2026 15:08:56 +0200 Subject: [PATCH] C#: Update the dispatch logic to account for all instance operator calls. --- .../semmle/code/csharp/dispatch/Dispatch.qll | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll b/csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll index 15a64d12b49..f1df963d72b 100644 --- a/csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll +++ b/csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll @@ -73,6 +73,19 @@ class DispatchCall extends Internal::TDispatchCall { } } +abstract private class InstanceOperatorCall extends OperatorCall { + abstract Expr getQualifier(); +} + +private class InstanceCompoundAssignment extends InstanceOperatorCall instanceof CompoundAssignmentOperatorCall +{ + override Expr getQualifier() { result = CompoundAssignmentOperatorCall.super.getQualifier() } +} + +private class InstanceMutator extends InstanceOperatorCall instanceof InstanceMutatorOperatorCall { + override Expr getQualifier() { result = InstanceMutatorOperatorCall.super.getQualifier() } +} + /** Internal implementation details. */ private module Internal { private import OverridableCallable @@ -101,9 +114,9 @@ private module Internal { } or TDispatchOperatorCall(OperatorCall oc) { not oc.isLateBound() and - not oc instanceof CompoundAssignmentOperatorCall + not oc instanceof InstanceOperatorCall } or - TDispatchCompoundAssignmentOperatorCall(CompoundAssignmentOperatorCall caoc) or + TDispatchInstanceOperatorCall(InstanceOperatorCall caoc) or TDispatchReflectionCall(MethodCall mc, string name, Expr object, Expr qualifier, int args) { isReflectionCall(mc, name, object, qualifier, args) } or @@ -890,12 +903,10 @@ private module Internal { override Operator getAStaticTarget() { result = this.getCall().getTarget() } } - private class DispatchCompoundAssignmentOperatorCall extends DispatchOverridableCall, - TDispatchCompoundAssignmentOperatorCall + private class DispatchInstanceOperatorCall extends DispatchOverridableCall, + TDispatchInstanceOperatorCall { - override CompoundAssignmentOperatorCall getCall() { - this = TDispatchCompoundAssignmentOperatorCall(result) - } + override InstanceOperatorCall getCall() { this = TDispatchInstanceOperatorCall(result) } override Expr getArgument(int i) { result = this.getCall().getArgument(i) }