Skip to content

Commit 5376eb8

Browse files
committed
C#: Convert System.String flow to CSV format.
1 parent df482a9 commit 5376eb8

File tree

2 files changed

+126
-136
lines changed

2 files changed

+126
-136
lines changed

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

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -535,142 +535,6 @@ class SystemIOStringReaderFlow extends LibraryTypeDataFlow, SystemIOStringReader
535535
}
536536
}
537537

538-
/** Data flow for `System.String`. */
539-
class SystemStringFlow extends LibraryTypeDataFlow, SystemStringClass {
540-
override predicate callableFlow(
541-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
542-
SourceDeclarationCallable c, boolean preservesValue
543-
) {
544-
this.constructorFlow(source, sourceAp, sink, sinkAp, c) and
545-
preservesValue = false
546-
or
547-
this.methodFlow(source, sourceAp, sink, sinkAp, c, preservesValue)
548-
}
549-
550-
private predicate constructorFlow(
551-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
552-
Constructor c
553-
) {
554-
c = this.getAMember() and
555-
c.getParameter(0).getType().(ArrayType).getElementType() instanceof CharType and
556-
source = TCallableFlowSourceArg(0) and
557-
sourceAp = AccessPath::element() and
558-
sink = TCallableFlowSinkReturn() and
559-
sinkAp = AccessPath::empty()
560-
}
561-
562-
private predicate methodFlow(
563-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
564-
SourceDeclarationMethod m, boolean preservesValue
565-
) {
566-
m = this.getAMethod("ToString") and
567-
source = TCallableFlowSourceQualifier() and
568-
sourceAp = AccessPath::empty() and
569-
sink = TCallableFlowSinkReturn() and
570-
sinkAp = AccessPath::empty() and
571-
preservesValue = true
572-
or
573-
m = this.getSplitMethod() and
574-
source = TCallableFlowSourceQualifier() and
575-
sourceAp = AccessPath::empty() and
576-
sink = TCallableFlowSinkReturn() and
577-
sinkAp = AccessPath::element() and
578-
preservesValue = false
579-
or
580-
m = this.getReplaceMethod() and
581-
sourceAp = AccessPath::empty() and
582-
sinkAp = AccessPath::empty() and
583-
(
584-
source = TCallableFlowSourceQualifier() and
585-
sink = TCallableFlowSinkReturn() and
586-
preservesValue = false
587-
or
588-
source = TCallableFlowSourceArg(1) and
589-
sink = TCallableFlowSinkReturn() and
590-
preservesValue = false
591-
)
592-
or
593-
m = this.getSubstringMethod() and
594-
source = TCallableFlowSourceQualifier() and
595-
sourceAp = AccessPath::empty() and
596-
sink = TCallableFlowSinkReturn() and
597-
sinkAp = AccessPath::empty() and
598-
preservesValue = false
599-
or
600-
m = this.getCloneMethod() and
601-
source = TCallableFlowSourceQualifier() and
602-
sourceAp = AccessPath::empty() and
603-
sink = TCallableFlowSinkReturn() and
604-
sinkAp = AccessPath::empty() and
605-
preservesValue = true
606-
or
607-
m = this.getInsertMethod() and
608-
sourceAp = AccessPath::empty() and
609-
sinkAp = AccessPath::empty() and
610-
(
611-
source = TCallableFlowSourceQualifier() and
612-
sink = TCallableFlowSinkReturn() and
613-
preservesValue = false
614-
or
615-
source = TCallableFlowSourceArg(1) and
616-
sink = TCallableFlowSinkReturn() and
617-
preservesValue = false
618-
)
619-
or
620-
m = this.getNormalizeMethod() and
621-
source = TCallableFlowSourceQualifier() and
622-
sourceAp = AccessPath::empty() and
623-
sink = TCallableFlowSinkReturn() and
624-
sinkAp = AccessPath::empty() and
625-
preservesValue = false
626-
or
627-
m = this.getRemoveMethod() and
628-
source = TCallableFlowSourceQualifier() and
629-
sourceAp = AccessPath::empty() and
630-
sink = TCallableFlowSinkReturn() and
631-
sinkAp = AccessPath::empty() and
632-
preservesValue = false
633-
or
634-
m = this.getAMethod() and
635-
m.getName().regexpMatch("((ToLower|ToUpper)(Invariant)?)|(Trim(Start|End)?)|(Pad(Left|Right))") and
636-
source = TCallableFlowSourceQualifier() and
637-
sourceAp = AccessPath::empty() and
638-
sink = TCallableFlowSinkReturn() and
639-
sinkAp = AccessPath::empty() and
640-
preservesValue = false
641-
or
642-
m = this.getConcatMethod() and
643-
exists(int i |
644-
source = getFlowSourceArg(m, i, sourceAp) and
645-
sink = TCallableFlowSinkReturn() and
646-
sinkAp = AccessPath::empty() and
647-
preservesValue = false
648-
)
649-
or
650-
m = this.getCopyMethod() and
651-
source = TCallableFlowSourceArg(0) and
652-
sourceAp = AccessPath::empty() and
653-
sink = TCallableFlowSinkReturn() and
654-
sinkAp = AccessPath::empty() and
655-
preservesValue = true
656-
or
657-
m = this.getJoinMethod() and
658-
source = getFlowSourceArg(m, [0, 1], sourceAp) and
659-
sink = TCallableFlowSinkReturn() and
660-
sinkAp = AccessPath::empty() and
661-
preservesValue = false
662-
or
663-
m = this.getFormatMethod() and
664-
exists(int i |
665-
(m.getParameter(0).getType() instanceof SystemIFormatProviderInterface implies i != 0) and
666-
source = getFlowSourceArg(m, i, sourceAp) and
667-
sink = TCallableFlowSinkReturn() and
668-
sinkAp = AccessPath::empty() and
669-
preservesValue = false
670-
)
671-
}
672-
}
673-
674538
/** Data flow for `System.Text.StringBuilder`. */
675539
class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringBuilderClass {
676540
override predicate callableFlow(

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

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,132 @@ class SystemStringClass extends StringType {
492492
}
493493
}
494494

495+
/** Data flow for `System.String`. */
496+
private class SystemStringFlowModelCsv extends SummaryModelCsv {
497+
override predicate row(string row) {
498+
row =
499+
[
500+
"System;String;false;Clone;();;Argument[-1];ReturnValue;value",
501+
"System;String;false;Concat;(System.Collections.Generic.IEnumerable<System.String>);;Element of Argument[0];ReturnValue;taint",
502+
"System;String;false;Concat;(System.Object);;Argument[0];ReturnValue;taint",
503+
"System;String;false;Concat;(System.Object,System.Object);;Argument[0];ReturnValue;taint",
504+
"System;String;false;Concat;(System.Object,System.Object);;Argument[1];ReturnValue;taint",
505+
"System;String;false;Concat;(System.Object,System.Object,System.Object);;Argument[0];ReturnValue;taint",
506+
"System;String;false;Concat;(System.Object,System.Object,System.Object);;Argument[1];ReturnValue;taint",
507+
"System;String;false;Concat;(System.Object,System.Object,System.Object);;Argument[2];ReturnValue;taint",
508+
"System;String;false;Concat;(System.Object[]);;Element of Argument[0];ReturnValue;taint",
509+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[0];ReturnValue;taint",
510+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[1];ReturnValue;taint",
511+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[0];ReturnValue;taint",
512+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[1];ReturnValue;taint",
513+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[2];ReturnValue;taint",
514+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[0];ReturnValue;taint",
515+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[1];ReturnValue;taint",
516+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[2];ReturnValue;taint",
517+
"System;String;false;Concat;(System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>,System.ReadOnlySpan<System.Char>);;Argument[3];ReturnValue;taint",
518+
"System;String;false;Concat;(System.String,System.String);;Argument[0];ReturnValue;taint",
519+
"System;String;false;Concat;(System.String,System.String);;Argument[1];ReturnValue;taint",
520+
"System;String;false;Concat;(System.String,System.String,System.String);;Argument[0];ReturnValue;taint",
521+
"System;String;false;Concat;(System.String,System.String,System.String);;Argument[1];ReturnValue;taint",
522+
"System;String;false;Concat;(System.String,System.String,System.String);;Argument[2];ReturnValue;taint",
523+
"System;String;false;Concat;(System.String,System.String,System.String,System.String);;Argument[0];ReturnValue;taint",
524+
"System;String;false;Concat;(System.String,System.String,System.String,System.String);;Argument[1];ReturnValue;taint",
525+
"System;String;false;Concat;(System.String,System.String,System.String,System.String);;Argument[2];ReturnValue;taint",
526+
"System;String;false;Concat;(System.String,System.String,System.String,System.String);;Argument[3];ReturnValue;taint",
527+
"System;String;false;Concat;(System.String[]);;Element of Argument[0];ReturnValue;taint",
528+
"System;String;false;Concat<>;(System.Collections.Generic.IEnumerable<T>);;Element of Argument[0];ReturnValue;taint",
529+
"System;String;false;Copy;(System.String);;Argument[0];ReturnValue;value",
530+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object);;Argument[1];ReturnValue;taint",
531+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object);;Argument[2];ReturnValue;taint",
532+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object,System.Object);;Argument[1];ReturnValue;taint",
533+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object,System.Object);;Argument[2];ReturnValue;taint",
534+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object,System.Object);;Argument[3];ReturnValue;taint",
535+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object,System.Object,System.Object);;Argument[1];ReturnValue;taint",
536+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object,System.Object,System.Object);;Argument[2];ReturnValue;taint",
537+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object,System.Object,System.Object);;Argument[3];ReturnValue;taint",
538+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object,System.Object,System.Object);;Argument[4];ReturnValue;taint",
539+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object[]);;Argument[1];ReturnValue;taint",
540+
"System;String;false;Format;(System.IFormatProvider,System.String,System.Object[]);;Element of Argument[2];ReturnValue;taint",
541+
"System;String;false;Format;(System.String,System.Object);;Argument[0];ReturnValue;taint",
542+
"System;String;false;Format;(System.String,System.Object);;Argument[1];ReturnValue;taint",
543+
"System;String;false;Format;(System.String,System.Object,System.Object);;Argument[0];ReturnValue;taint",
544+
"System;String;false;Format;(System.String,System.Object,System.Object);;Argument[1];ReturnValue;taint",
545+
"System;String;false;Format;(System.String,System.Object,System.Object);;Argument[2];ReturnValue;taint",
546+
"System;String;false;Format;(System.String,System.Object,System.Object,System.Object);;Argument[0];ReturnValue;taint",
547+
"System;String;false;Format;(System.String,System.Object,System.Object,System.Object);;Argument[1];ReturnValue;taint",
548+
"System;String;false;Format;(System.String,System.Object,System.Object,System.Object);;Argument[2];ReturnValue;taint",
549+
"System;String;false;Format;(System.String,System.Object,System.Object,System.Object);;Argument[3];ReturnValue;taint",
550+
"System;String;false;Format;(System.String,System.Object[]);;Argument[0];ReturnValue;taint",
551+
"System;String;false;Format;(System.String,System.Object[]);;Element of Argument[1];ReturnValue;taint",
552+
"System;String;false;GetEnumerator;();;Element of Argument[-1];Property[System.CharEnumerator.Current] of ReturnValue;value",
553+
"System;String;false;GetEnumerator;();;Element of Argument[-1];Property[System.Collections.Generic.IEnumerator<>.Current] of ReturnValue;value",
554+
"System;String;false;Insert;(System.Int32,System.String);;Argument[1];ReturnValue;taint",
555+
"System;String;false;Insert;(System.Int32,System.String);;Argument[-1];ReturnValue;taint",
556+
"System;String;false;Join;(System.Char,System.Object[]);;Argument[0];ReturnValue;taint",
557+
"System;String;false;Join;(System.Char,System.Object[]);;Element of Argument[1];ReturnValue;taint",
558+
"System;String;false;Join;(System.Char,System.String[]);;Argument[0];ReturnValue;taint",
559+
"System;String;false;Join;(System.Char,System.String[]);;Element of Argument[1];ReturnValue;taint",
560+
"System;String;false;Join;(System.Char,System.String[],System.Int32,System.Int32);;Argument[0];ReturnValue;taint",
561+
"System;String;false;Join;(System.Char,System.String[],System.Int32,System.Int32);;Element of Argument[1];ReturnValue;taint",
562+
"System;String;false;Join;(System.String,System.Collections.Generic.IEnumerable<System.String>);;Argument[0];ReturnValue;taint",
563+
"System;String;false;Join;(System.String,System.Collections.Generic.IEnumerable<System.String>);;Element of Argument[1];ReturnValue;taint",
564+
"System;String;false;Join;(System.String,System.Object[]);;Argument[0];ReturnValue;taint",
565+
"System;String;false;Join;(System.String,System.Object[]);;Element of Argument[1];ReturnValue;taint",
566+
"System;String;false;Join;(System.String,System.String[]);;Argument[0];ReturnValue;taint",
567+
"System;String;false;Join;(System.String,System.String[]);;Element of Argument[1];ReturnValue;taint",
568+
"System;String;false;Join;(System.String,System.String[],System.Int32,System.Int32);;Argument[0];ReturnValue;taint",
569+
"System;String;false;Join;(System.String,System.String[],System.Int32,System.Int32);;Element of Argument[1];ReturnValue;taint",
570+
"System;String;false;Join<>;(System.Char,System.Collections.Generic.IEnumerable<T>);;Argument[0];ReturnValue;taint",
571+
"System;String;false;Join<>;(System.Char,System.Collections.Generic.IEnumerable<T>);;Element of Argument[1];ReturnValue;taint",
572+
"System;String;false;Join<>;(System.String,System.Collections.Generic.IEnumerable<T>);;Argument[0];ReturnValue;taint",
573+
"System;String;false;Join<>;(System.String,System.Collections.Generic.IEnumerable<T>);;Element of Argument[1];ReturnValue;taint",
574+
"System;String;false;Normalize;();;Argument[-1];ReturnValue;taint",
575+
"System;String;false;Normalize;(System.Text.NormalizationForm);;Argument[-1];ReturnValue;taint",
576+
"System;String;false;PadLeft;(System.Int32);;Argument[-1];ReturnValue;taint",
577+
"System;String;false;PadLeft;(System.Int32,System.Char);;Argument[-1];ReturnValue;taint",
578+
"System;String;false;PadRight;(System.Int32);;Argument[-1];ReturnValue;taint",
579+
"System;String;false;PadRight;(System.Int32,System.Char);;Argument[-1];ReturnValue;taint",
580+
"System;String;false;Remove;(System.Int32);;Argument[-1];ReturnValue;taint",
581+
"System;String;false;Remove;(System.Int32,System.Int32);;Argument[-1];ReturnValue;taint",
582+
"System;String;false;Replace;(System.Char,System.Char);;Argument[1];ReturnValue;taint",
583+
"System;String;false;Replace;(System.Char,System.Char);;Argument[-1];ReturnValue;taint",
584+
"System;String;false;Replace;(System.String,System.String);;Argument[1];ReturnValue;taint",
585+
"System;String;false;Replace;(System.String,System.String);;Argument[-1];ReturnValue;taint",
586+
"System;String;false;Split;(System.Char,System.Int32,System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
587+
"System;String;false;Split;(System.Char,System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
588+
"System;String;false;Split;(System.Char[]);;Argument[-1];Element of ReturnValue;taint",
589+
"System;String;false;Split;(System.Char[],System.Int32);;Argument[-1];Element of ReturnValue;taint",
590+
"System;String;false;Split;(System.Char[],System.Int32,System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
591+
"System;String;false;Split;(System.Char[],System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
592+
"System;String;false;Split;(System.String,System.Int32,System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
593+
"System;String;false;Split;(System.String,System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
594+
"System;String;false;Split;(System.String[],System.Int32,System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
595+
"System;String;false;Split;(System.String[],System.StringSplitOptions);;Argument[-1];Element of ReturnValue;taint",
596+
"System;String;false;String;(System.Char[]);;Element of Argument[0];ReturnValue;taint",
597+
"System;String;false;String;(System.Char[],System.Int32,System.Int32);;Element of Argument[0];ReturnValue;taint",
598+
"System;String;false;Substring;(System.Int32);;Argument[-1];ReturnValue;taint",
599+
"System;String;false;Substring;(System.Int32,System.Int32);;Argument[-1];ReturnValue;taint",
600+
"System;String;false;ToLower;();;Argument[-1];ReturnValue;taint",
601+
"System;String;false;ToLower;(System.Globalization.CultureInfo);;Argument[-1];ReturnValue;taint",
602+
"System;String;false;ToLowerInvariant;();;Argument[-1];ReturnValue;taint",
603+
"System;String;false;ToString;();;Argument[-1];ReturnValue;value",
604+
"System;String;false;ToString;(System.IFormatProvider);;Argument[-1];ReturnValue;value",
605+
"System;String;false;ToUpper;();;Argument[-1];ReturnValue;taint",
606+
"System;String;false;ToUpper;(System.Globalization.CultureInfo);;Argument[-1];ReturnValue;taint",
607+
"System;String;false;ToUpperInvariant;();;Argument[-1];ReturnValue;taint",
608+
"System;String;false;Trim;();;Argument[-1];ReturnValue;taint",
609+
"System;String;false;Trim;(System.Char);;Argument[-1];ReturnValue;taint",
610+
"System;String;false;Trim;(System.Char[]);;Argument[-1];ReturnValue;taint",
611+
"System;String;false;TrimEnd;();;Argument[-1];ReturnValue;taint",
612+
"System;String;false;TrimEnd;(System.Char);;Argument[-1];ReturnValue;taint",
613+
"System;String;false;TrimEnd;(System.Char[]);;Argument[-1];ReturnValue;taint",
614+
"System;String;false;TrimStart;();;Argument[-1];ReturnValue;taint",
615+
"System;String;false;TrimStart;(System.Char);;Argument[-1];ReturnValue;taint",
616+
"System;String;false;TrimStart;(System.Char[]);;Argument[-1];ReturnValue;taint",
617+
]
618+
}
619+
}
620+
495621
/** A `ToString()` method. */
496622
class ToStringMethod extends Method {
497623
ToStringMethod() { this = any(SystemObjectClass c).getToStringMethod().getAnOverrider*() }

0 commit comments

Comments
 (0)