Skip to content

Commit 4128f56

Browse files
authored
Merge pull request #7289 from michaelnebel/csharp-mad-as-csv
C#: Convert some of the existing flow summaries to CSV
2 parents 802faf1 + 7ad52e1 commit 4128f56

File tree

4 files changed

+34
-76
lines changed

4 files changed

+34
-76
lines changed

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

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -499,82 +499,6 @@ private module FrameworkDataFlowAdaptor {
499499
}
500500
}
501501

502-
/** Data flow for `System.Boolean`. */
503-
class SystemBooleanFlow extends LibraryTypeDataFlow, SystemBooleanStruct {
504-
override predicate callableFlow(
505-
CallableFlowSource source, CallableFlowSink sink, SourceDeclarationCallable c,
506-
boolean preservesValue
507-
) {
508-
this.methodFlow(source, sink, c) and
509-
preservesValue = false
510-
}
511-
512-
private predicate methodFlow(
513-
CallableFlowSource source, CallableFlowSink sink, SourceDeclarationMethod m
514-
) {
515-
m = this.getParseMethod() and
516-
(
517-
source = TCallableFlowSourceArg(0) and
518-
sink = TCallableFlowSinkReturn()
519-
)
520-
or
521-
m = this.getTryParseMethod() and
522-
(
523-
source = TCallableFlowSourceArg(0) and
524-
(
525-
sink = TCallableFlowSinkReturn()
526-
or
527-
sink = TCallableFlowSinkArg(any(int i | m.getParameter(i).isOutOrRef()))
528-
)
529-
)
530-
}
531-
}
532-
533-
/** Data flow for `System.Uri`. */
534-
class SystemUriFlow extends LibraryTypeDataFlow, SystemUriClass {
535-
override predicate callableFlow(
536-
CallableFlowSource source, CallableFlowSink sink, SourceDeclarationCallable c,
537-
boolean preservesValue
538-
) {
539-
(
540-
this.constructorFlow(source, sink, c)
541-
or
542-
this.methodFlow(source, sink, c)
543-
or
544-
exists(Property p |
545-
this.propertyFlow(p) and
546-
source = TCallableFlowSourceQualifier() and
547-
sink = TCallableFlowSinkReturn() and
548-
c = p.getGetter()
549-
)
550-
) and
551-
preservesValue = false
552-
}
553-
554-
private predicate constructorFlow(CallableFlowSource source, CallableFlowSink sink, Constructor c) {
555-
c = this.getAMember() and
556-
c.getParameter(0).getType() instanceof StringType and
557-
source = TCallableFlowSourceArg(0) and
558-
sink = TCallableFlowSinkReturn()
559-
}
560-
561-
private predicate methodFlow(
562-
CallableFlowSource source, CallableFlowSink sink, SourceDeclarationMethod m
563-
) {
564-
m = this.getAMethod("ToString") and
565-
source = TCallableFlowSourceQualifier() and
566-
sink = TCallableFlowSinkReturn()
567-
}
568-
569-
private predicate propertyFlow(Property p) {
570-
p = this.getPathAndQueryProperty()
571-
or
572-
p = this.getQueryProperty()
573-
or
574-
p = this.getOriginalStringProperty()
575-
}
576-
}
577-
578502
/** Data flow for `System.IO.StringReader`. */
579503
class SystemIOStringReaderFlow extends LibraryTypeDataFlow, SystemIOStringReaderClass {
580504
override predicate callableFlow(

csharp/ql/lib/semmle/code/csharp/frameworks/System.qll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ class SystemBooleanStruct extends BoolType {
9292
}
9393
}
9494

95+
/** Data flow for `System.Boolean`. */
96+
private class SystemBooleanFlowModelCsv extends SummaryModelCsv {
97+
override predicate row(string row) {
98+
row =
99+
[
100+
"System;Boolean;false;Parse;(System.String);;Argument[0];ReturnValue;taint",
101+
"System;Boolean;false;TryParse;(System.String,System.Boolean);;Argument[0];Argument[1];taint",
102+
"System;Boolean;false;TryParse;(System.String,System.Boolean);;Argument[0];ReturnValue;taint",
103+
"System;Boolean;false;TryParse;(System.ReadOnlySpan<System.Char>,System.Boolean);;Element of Argument[0];Argument[1];taint",
104+
"System;Boolean;false;TryParse;(System.ReadOnlySpan<System.Char>,System.Boolean);;Element of Argument[0];ReturnValue;taint",
105+
]
106+
}
107+
}
108+
95109
/** The `System.Convert` class. */
96110
class SystemConvertClass extends SystemClass {
97111
SystemConvertClass() { this.hasName("Convert") }
@@ -539,6 +553,22 @@ class SystemUriClass extends SystemClass {
539553
}
540554
}
541555

556+
/** Data flow for `System.Uri`. */
557+
private class SystemUriFlowModelCsv extends SummaryModelCsv {
558+
override predicate row(string row) {
559+
row =
560+
[
561+
"System;Uri;false;ToString;();;Argument[-1];ReturnValue;taint",
562+
"System;Uri;false;Uri;(System.String);;Argument[0];ReturnValue;taint",
563+
"System;Uri;false;Uri;(System.String,System.Boolean);;Argument[0];ReturnValue;taint",
564+
"System;Uri;false;Uri;(System.String,System.UriKind);;Argument[0];ReturnValue;taint",
565+
"System;Uri;false;get_OriginalString;();;Argument[-1];ReturnValue;taint",
566+
"System;Uri;false;get_PathAndQuery;();;Argument[-1];ReturnValue;taint",
567+
"System;Uri;false;get_Query;();;Argument[-1];ReturnValue;taint",
568+
]
569+
}
570+
}
571+
542572
/** The `System.ValueType` class. */
543573
class SystemValueTypeClass extends SystemClass {
544574
SystemValueTypeClass() { this.hasName("ValueType") }

csharp/ql/test/library-tests/dataflow/library/FlowSummaries.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,8 @@
23302330
| System;Array;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value |
23312331
| System;Array;false;set_Item;(System.Int32,System.Object);;Argument[1];Element of Argument[-1];value |
23322332
| System;Boolean;false;Parse;(System.String);;Argument[0];ReturnValue;taint |
2333+
| System;Boolean;false;TryParse;(System.ReadOnlySpan<System.Char>,System.Boolean);;Element of Argument[0];Argument[1];taint |
2334+
| System;Boolean;false;TryParse;(System.ReadOnlySpan<System.Char>,System.Boolean);;Element of Argument[0];ReturnValue;taint |
23332335
| System;Boolean;false;TryParse;(System.String,System.Boolean);;Argument[0];Argument[1];taint |
23342336
| System;Boolean;false;TryParse;(System.String,System.Boolean);;Argument[0];ReturnValue;taint |
23352337
| System;Convert;false;ChangeType;(System.Object,System.Type);;Argument[0];ReturnValue;taint |

csharp/ql/test/library-tests/dataflow/library/FlowSummariesFiltered.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,8 @@
20042004
| System;Array;false;get_Item;(System.Int32);;Element of Argument[-1];ReturnValue;value |
20052005
| System;Array;false;set_Item;(System.Int32,System.Object);;Argument[1];Element of Argument[-1];value |
20062006
| System;Boolean;false;Parse;(System.String);;Argument[0];ReturnValue;taint |
2007+
| System;Boolean;false;TryParse;(System.ReadOnlySpan<System.Char>,System.Boolean);;Element of Argument[0];Argument[1];taint |
2008+
| System;Boolean;false;TryParse;(System.ReadOnlySpan<System.Char>,System.Boolean);;Element of Argument[0];ReturnValue;taint |
20072009
| System;Boolean;false;TryParse;(System.String,System.Boolean);;Argument[0];Argument[1];taint |
20082010
| System;Boolean;false;TryParse;(System.String,System.Boolean);;Argument[0];ReturnValue;taint |
20092011
| System;Convert;false;ChangeType;(System.Object,System.Type);;Argument[0];ReturnValue;taint |

0 commit comments

Comments
 (0)