Skip to content

Commit 83ccddf

Browse files
authored
Merge pull request #707 from hvitved/csharp/bounded-fast-tc
Approved by calumgrant
2 parents c57f8a6 + e5cbac5 commit 83ccddf

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

csharp/ql/src/semmle/code/csharp/dispatch/Dispatch.qll

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,6 @@ private module Internal {
269269
* types for a given expression.
270270
*/
271271
private module SimpleTypeDataFlow {
272-
// A temporary workaround to get the right join-order in `Sink::getASource()`
273-
private newtype ExprWrapper = TExprWrapper(Expr e)
274-
275-
private Expr unwrap(ExprWrapper ew) { ew = TExprWrapper(result) }
276-
277-
private ExprWrapper wrap(Expr e) { result = TExprWrapper(e) }
278-
279272
/**
280273
* Holds if type `t` may be imprecise, that is, an expression of type `t` may
281274
* in fact have a more precise type.
@@ -321,34 +314,27 @@ private module Internal {
321314
typeMayBeImprecise(succ.getType())
322315
}
323316

324-
private predicate step(ExprWrapper succ, ExprWrapper pred) {
325-
stepExpr(unwrap(succ), unwrap(pred))
326-
}
327-
328-
private predicate isSink(ExprWrapper ew) {
329-
exists(Expr e |
330-
e = unwrap(ew) |
331-
e = any(DynamicMemberAccess dma | isSink(wrap(dma))).getQualifier() or
332-
e = any(AccessorCall ac).getAnArgument() or
333-
e = any(DispatchReflectionOrDynamicCall c).getArgument(_) or
334-
e = any(MethodCall mc | mc.getTarget() = any(SystemObjectClass c).getGetTypeMethod()).getQualifier() or
335-
e = any(DispatchCallImpl c).getQualifier()
336-
)
337-
}
338-
339-
private predicate stepTC(ExprWrapper succ, ExprWrapper pred) =
340-
boundedFastTC(step/2, isSink/1)(succ, pred)
317+
private predicate stepTC(Expr succ, Expr pred) =
318+
fastTC(stepExpr/2)(succ, pred)
341319

342320
private class Source extends Expr {
343321
Source() { not stepExpr(this, _) }
344322
}
345323

346324
private class Sink extends Expr {
347-
Sink() { isSink(wrap(this)) }
348-
349-
Source getASource() {
350-
stepTC(wrap(this), wrap(result))
325+
Sink() {
326+
this = any(DynamicMemberAccess dma | dma instanceof Sink).getQualifier()
327+
or
328+
this = any(AccessorCall ac).getAnArgument()
329+
or
330+
this = any(DispatchReflectionOrDynamicCall c).getArgument(_)
331+
or
332+
this = any(MethodCall mc | mc.getTarget() = any(SystemObjectClass c).getGetTypeMethod()).getQualifier()
333+
or
334+
this = any(DispatchCallImpl c).getQualifier()
351335
}
336+
337+
Source getASource() { stepTC(this, result) }
352338
}
353339

354340
/** Holds if the expression `e` has an exact type. */
@@ -357,10 +343,7 @@ private module Internal {
357343
e instanceof BaseAccess
358344
}
359345

360-
/**
361-
* Gets a source type for expression `e`, using simple data flow. The
362-
* expression must be a member of the predicate `isSink()` above.
363-
*/
346+
/** Gets a source type for expression `e`, using simple data flow. */
364347
Type getASourceType(Sink e, boolean isExact) {
365348
exists(Source s |
366349
s = e.getASource() or

0 commit comments

Comments
 (0)