Skip to content

Commit 64eb0cc

Browse files
committed
C#: Implement ContentApprox
1 parent bc58cbe commit 64eb0cc

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,13 @@ private module Cached {
904904
TElementContent() or
905905
TSyntheticFieldContent(SyntheticField f)
906906

907+
cached
908+
newtype TContentApprox =
909+
TFieldApproxContent(string firstChar) { firstChar = approximateFieldContent(_) } or
910+
TPropertyApproxContent(string firstChar) { firstChar = approximatePropertyContent(_) } or
911+
TElementApproxContent() or
912+
TSyntheticFieldApproxContent()
913+
907914
pragma[nomagic]
908915
private predicate commonSubTypeGeneral(DataFlowTypeOrUnifiable t1, RelevantDataFlowType t2) {
909916
not t1 instanceof Gvn::TypeParameterGvnType and
@@ -2246,6 +2253,46 @@ predicate allowParameterReturnInSelf(ParameterNode p) {
22462253
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(p)
22472254
}
22482255

2256+
/** An approximated `Content`. */
2257+
class ContentApprox extends TContentApprox {
2258+
/** Gets a textual representation of this approximated `Content`. */
2259+
string toString() {
2260+
exists(string firstChar |
2261+
this = TFieldApproxContent(firstChar) and result = "approximated field " + firstChar
2262+
)
2263+
or
2264+
exists(string firstChar |
2265+
this = TPropertyApproxContent(firstChar) and result = "approximated property " + firstChar
2266+
)
2267+
or
2268+
this = TElementApproxContent() and result = "element"
2269+
or
2270+
this = TSyntheticFieldApproxContent() and result = "approximated synthetic field"
2271+
}
2272+
}
2273+
2274+
/** Gets a string for approximating the name of a field. */
2275+
private string approximateFieldContent(FieldContent fc) {
2276+
result = fc.getField().getName().prefix(1)
2277+
}
2278+
2279+
/** Gets a string for approximating the name of a property. */
2280+
private string approximatePropertyContent(PropertyContent pc) {
2281+
result = pc.getProperty().getName().prefix(1)
2282+
}
2283+
2284+
/** Gets an approximated value for content `c`. */
2285+
pragma[nomagic]
2286+
ContentApprox getContentApprox(Content c) {
2287+
result = TFieldApproxContent(approximateFieldContent(c))
2288+
or
2289+
result = TPropertyApproxContent(approximatePropertyContent(c))
2290+
or
2291+
c instanceof ElementContent and result = TElementApproxContent()
2292+
or
2293+
c instanceof SyntheticFieldContent and result = TSyntheticFieldApproxContent()
2294+
}
2295+
22492296
/**
22502297
* A module importing the modules that provide synthetic field declarations,
22512298
* ensuring that they are visible to the taint tracking / data flow library.

0 commit comments

Comments
 (0)