Skip to content

Commit c0b61d7

Browse files
authored
Merge pull request #7370 from michaelnebel/csharp-mad-textreader
C#: Flow summaries for virtual members in abstract classes should also apply to overrides.
2 parents 124aac2 + ba23393 commit c0b61d7

File tree

8 files changed

+158
-178
lines changed

8 files changed

+158
-178
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,22 @@ class Virtualizable extends Member, @virtualizable {
362362
/** Holds if this member implements (transitively) an interface member. */
363363
predicate implements() { exists(this.getAnUltimateImplementee()) }
364364

365+
/**
366+
* Holds if this member overrides or implements (transitively)
367+
* `that` member.
368+
*/
369+
predicate overridesOrImplements(Virtualizable that) {
370+
this.getOverridee+() = that or
371+
this.getAnUltimateImplementee() = that
372+
}
373+
365374
/**
366375
* Holds if this member overrides or implements (reflexively, transitively)
367376
* `that` member.
368377
*/
369378
predicate overridesOrImplementsOrEquals(Virtualizable that) {
370379
this = that or
371-
this.getOverridee+() = that or
372-
this.getAnUltimateImplementee() = that
380+
this.overridesOrImplements(that)
373381
}
374382
}
375383

csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ private module Frameworks {
9898
private import semmle.code.csharp.frameworks.system.collections.Generic
9999
private import semmle.code.csharp.frameworks.system.web.ui.WebControls
100100
private import semmle.code.csharp.frameworks.JsonNET
101+
private import semmle.code.csharp.frameworks.system.IO
101102
}
102103

103104
/**

csharp/ql/lib/semmle/code/csharp/dataflow/LibraryTypeDataFlow.qll

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -503,37 +503,6 @@ private module FrameworkDataFlowAdaptor {
503503
}
504504
}
505505

506-
/** Data flow for `System.IO.StringReader`. */
507-
class SystemIOStringReaderFlow extends LibraryTypeDataFlow, SystemIOStringReaderClass {
508-
override predicate callableFlow(
509-
CallableFlowSource source, CallableFlowSink sink, SourceDeclarationCallable c,
510-
boolean preservesValue
511-
) {
512-
(
513-
this.constructorFlow(source, sink, c)
514-
or
515-
this.methodFlow(source, sink, c)
516-
) and
517-
preservesValue = false
518-
}
519-
520-
private predicate constructorFlow(CallableFlowSource source, CallableFlowSink sink, Constructor c) {
521-
c = this.getAMember() and
522-
c.getParameter(0).getType() instanceof StringType and
523-
source = TCallableFlowSourceArg(0) and
524-
sink = TCallableFlowSinkReturn()
525-
}
526-
527-
private predicate methodFlow(
528-
CallableFlowSource source, CallableFlowSink sink, SourceDeclarationMethod m
529-
) {
530-
m.getDeclaringType() = this.getABaseType*() and
531-
m.getName().matches("Read%") and
532-
source = TCallableFlowSourceQualifier() and
533-
sink = TCallableFlowSinkReturn()
534-
}
535-
}
536-
537506
/** Data flow for `System.Text.StringBuilder`. */
538507
class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringBuilderClass {
539508
override predicate clearsContent(

csharp/ql/lib/semmle/code/csharp/frameworks/system/IO.qll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import csharp
44
private import semmle.code.csharp.frameworks.System
5+
private import semmle.code.csharp.dataflow.ExternalFlow
56

67
/** The `System.IO` namespace. */
78
class SystemIONamespace extends Namespace {
@@ -41,11 +42,40 @@ class SystemIOPathClass extends SystemIOClass {
4142
SystemIOPathClass() { this.hasName("Path") }
4243
}
4344

45+
/** Data flow for `System.IO.TextReader`. */
46+
private class SystemIOTextReaderFlowModelCsv extends SummaryModelCsv {
47+
override predicate row(string row) {
48+
row =
49+
[
50+
"System.IO;TextReader;true;Read;();;Argument[-1];ReturnValue;taint",
51+
"System.IO;TextReader;true;Read;(System.Char[],System.Int32,System.Int32);;Argument[-1];ReturnValue;taint",
52+
"System.IO;TextReader;true;Read;(System.Span<System.Char>);;Argument[-1];ReturnValue;taint",
53+
"System.IO;TextReader;true;ReadAsync;(System.Char[],System.Int32,System.Int32);;Argument[-1];ReturnValue;taint",
54+
"System.IO;TextReader;true;ReadAsync;(System.Memory<System.Char>,System.Threading.CancellationToken);;Argument[-1];ReturnValue;taint",
55+
"System.IO;TextReader;true;ReadBlock;(System.Char[],System.Int32,System.Int32);;Argument[-1];ReturnValue;taint",
56+
"System.IO;TextReader;true;ReadBlock;(System.Span<System.Char>);;Argument[-1];ReturnValue;taint",
57+
"System.IO;TextReader;true;ReadBlockAsync;(System.Char[],System.Int32,System.Int32);;Argument[-1];ReturnValue;taint",
58+
"System.IO;TextReader;true;ReadBlockAsync;(System.Memory<System.Char>,System.Threading.CancellationToken);;Argument[-1];ReturnValue;taint",
59+
"System.IO;TextReader;true;ReadLine;();;Argument[-1];ReturnValue;taint",
60+
"System.IO;TextReader;true;ReadLineAsync;();;Argument[-1];ReturnValue;taint",
61+
"System.IO;TextReader;true;ReadToEnd;();;Argument[-1];ReturnValue;taint",
62+
"System.IO;TextReader;true;ReadToEndAsync;();;Argument[-1];ReturnValue;taint",
63+
]
64+
}
65+
}
66+
4467
/** The `System.IO.StringReader` class. */
4568
class SystemIOStringReaderClass extends SystemIOClass {
4669
SystemIOStringReaderClass() { this.hasName("StringReader") }
4770
}
4871

72+
/** Data flow for `System.IO.StringReader` */
73+
private class SystemIOStringReaderFlowModelCsv extends SummaryModelCsv {
74+
override predicate row(string row) {
75+
row = "System.IO;StringReader;false;StringReader;(System.String);;Argument[0];ReturnValue;taint"
76+
}
77+
}
78+
4979
/** The `System.IO.Stream` class. */
5080
class SystemIOStreamClass extends SystemIOClass {
5181
SystemIOStreamClass() { this.hasName("Stream") }

0 commit comments

Comments
 (0)