Skip to content

Commit c139850

Browse files
authored
Merge pull request #8609 from michaelnebel/csharp/operatorsummaries
C#: Operator flow
2 parents 9309a65 + 8238c99 commit c139850

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

csharp/ql/lib/semmle/code/csharp/Callable.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ class Operator extends Callable, Member, Attributable, @operator {
460460
override string toString() { result = Callable.super.toString() }
461461

462462
override Parameter getRawParameter(int i) { result = this.getParameter(i) }
463+
464+
override predicate hasQualifiedName(string qualifier, string name) {
465+
super.hasQualifiedName(qualifier, _) and
466+
name = this.getFunctionName()
467+
}
463468
}
464469

465470
/** A clone method on a record. */

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,13 +2070,14 @@ module Csv {
20702070

20712071
/** Computes the first 6 columns for CSV rows of `c`. */
20722072
string asPartialModel(DataFlowCallable c) {
2073-
exists(string namespace, string type |
2073+
exists(string namespace, string type, string name |
20742074
c.getDeclaringType().hasQualifiedName(namespace, type) and
2075+
c.hasQualifiedName(_, name) and
20752076
result =
20762077
namespace + ";" //
20772078
+ type + ";" //
20782079
+ getCallableOverride(c) + ";" //
2079-
+ c.getName() + ";" //
2080+
+ name + ";" //
20802081
+ "(" + parameterQualifiedTypeNamesToString(c) + ")" //
20812082
+ /* ext + */ ";" //
20822083
)

csharp/ql/src/utils/model-generator/internal/CaptureModelsSpecific.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class Type = CS::Type;
2121
*/
2222
private predicate isRelevantForModels(CS::Callable api) {
2323
[api.(CS::Modifiable), api.(CS::Accessor).getDeclaration()].isEffectivelyPublic() and
24-
not api instanceof Util::MainMethod
24+
not api instanceof CS::ConversionOperator and
25+
not api instanceof Util::MainMethod and
26+
api.getDeclaringType().getNamespace().getQualifiedName() != ""
2527
}
2628

2729
/**

csharp/ql/test/utils/model-generator/CaptureSummaryModels.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@
2828
| Summaries;IEnumerableFlow;false;ReturnFieldInIEnumerable;();Argument[Qualifier];ReturnValue;taint |
2929
| Summaries;IEnumerableFlow;false;ReturnIEnumerable;(System.Collections.Generic.IEnumerable<System.String>);Argument[0].Element;ReturnValue;taint |
3030
| Summaries;IEnumerableFlow;false;ReturnIEnumerableElement;(System.Collections.Generic.IEnumerable<System.Object>);Argument[0].Element;ReturnValue;taint |
31+
| Summaries;OperatorFlow;false;OperatorFlow;(System.Object);Argument[0];Argument[Qualifier];taint |
32+
| Summaries;OperatorFlow;false;op_Addition;(Summaries.OperatorFlow,Summaries.OperatorFlow);Argument[0];ReturnValue;taint |

csharp/ql/test/utils/model-generator/Summaries.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,39 @@ public int ReturnParam0(int input0, int input1)
171171
{
172172
return input0;
173173
}
174+
}
175+
176+
public class OperatorFlow
177+
{
178+
public readonly object Field;
179+
180+
public OperatorFlow(object o)
181+
{
182+
Field = o;
183+
}
184+
185+
// Flow Summary.
186+
public static OperatorFlow operator +(OperatorFlow a, OperatorFlow b)
187+
{
188+
return a;
189+
}
190+
191+
// No flow summary.
192+
public static OperatorFlow operator ++(OperatorFlow a)
193+
{
194+
return new OperatorFlow(new object());
195+
}
196+
197+
// No flow summary as this is an implicit conversion operator.
198+
public static implicit operator OperatorFlow(int i)
199+
{
200+
return new OperatorFlow(i);
201+
}
202+
203+
// No flow summary as this is an explicit conversion operator.
204+
public static explicit operator OperatorFlow(byte b)
205+
{
206+
return new OperatorFlow(b);
207+
}
208+
174209
}

0 commit comments

Comments
 (0)