Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29fb23e

Browse files
committed
C#: Add flow summaries for System.[Value]Tuple
1 parent 4125241 commit 29fb23e

4 files changed

Lines changed: 458 additions & 3 deletions

File tree

csharp/ql/src/semmle/code/csharp/Type.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
258258
getAMember().(Virtualizable).getOverridee() = v
259259
}
260260

261+
/** Gets a field (or member constant) with the given name. */
262+
Field getField(string name) { result = getAMember() and result.hasName(name) }
263+
261264
/** Gets a field (or member constant) of this type, if any. */
262-
Field getAField() { result = getAMember() }
265+
Field getAField() { result = this.getField(_) }
263266

264267
/** Gets a member constant of this type, if any. */
265268
MemberConstant getAConstant() { result = getAMember() }

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,62 @@ class SystemCollectionsGenericKeyValuePairStructFlow extends LibraryTypeDataFlow
16791679
}
16801680
}
16811681

1682+
/** Data flow for `System.[Value]Tuple<,...,>`. */
1683+
class SystemTupleFlow extends LibraryTypeDataFlow, ValueOrRefType {
1684+
SystemTupleFlow() {
1685+
this.getNamespace() instanceof SystemNamespace and
1686+
this.getName().regexpMatch("(Value)?Tuple(<,*>)?")
1687+
or
1688+
this instanceof TupleType
1689+
}
1690+
1691+
private AccessPath getItemAccessPath(int i) {
1692+
i in [1 .. count(this.getAMember())] and
1693+
result in [AccessPath::field(this.getField("Item" + i)),
1694+
AccessPath::property(this.getProperty("Item" + i))]
1695+
}
1696+
1697+
override predicate callableFlow(
1698+
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
1699+
SourceDeclarationCallable c, boolean preservesValue
1700+
) {
1701+
preservesValue = true and
1702+
(
1703+
exists(SystemTupleFlow t, int i |
1704+
source = getFlowSourceArg(c, i - 1, _) and
1705+
sourceAp = AccessPath::empty() and
1706+
sink = TCallableFlowSinkReturn() and
1707+
sinkAp = t.getItemAccessPath(i)
1708+
|
1709+
c.(Constructor).getDeclaringType() = this and
1710+
t = this
1711+
or
1712+
c = this.getAMethod(any(string name | name.regexpMatch("Create(<,*>)?"))) and
1713+
t = c.getReturnType().getSourceDeclaration()
1714+
)
1715+
or
1716+
c =
1717+
any(ExtensionMethod m |
1718+
m.hasName("Deconstruct") and
1719+
this = m.getExtendedType().getSourceDeclaration() and
1720+
exists(int i |
1721+
m.getParameter(i).isOut() and
1722+
source = getFlowSourceArg(c, 0, _) and
1723+
sourceAp = this.getItemAccessPath(i) and
1724+
sink = TCallableFlowSinkArg(i) and
1725+
sinkAp = AccessPath::empty()
1726+
)
1727+
)
1728+
or
1729+
c = this.getAnIndexer().getGetter() and
1730+
source = TCallableFlowSourceQualifier() and
1731+
sourceAp = this.getItemAccessPath(_) and
1732+
sink = TCallableFlowSinkReturn() and
1733+
sinkAp = AccessPath::empty()
1734+
)
1735+
}
1736+
}
1737+
16821738
/** Data flow for `System.Threading.Tasks.Task`. */
16831739
class SystemThreadingTasksTaskFlow extends LibraryTypeDataFlow, SystemThreadingTasksTaskClass {
16841740
override predicate callableFlow(

0 commit comments

Comments
 (0)