mirror of
https://github.com/github/codeql.git
synced 2026-01-08 12:10:22 +01:00
C#: Deprecate Assignable(Read)::getAReachableRead
This commit is contained in:
@@ -6,6 +6,7 @@ import semmle.code.csharp.frameworks.System
|
||||
* Holds if expression `e`, of type `t`, invokes `ToString()` either explicitly
|
||||
* or implicitly.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
predicate invokesToString(Expr e, ValueOrRefType t) {
|
||||
// Explicit invocation
|
||||
exists(MethodCall mc | mc.getQualifier() = e |
|
||||
@@ -20,20 +21,24 @@ predicate invokesToString(Expr e, ValueOrRefType t) {
|
||||
// Implicit invocation via forwarder method
|
||||
t = e.stripCasts().getType() and
|
||||
not t instanceof StringType and
|
||||
exists(Parameter p |
|
||||
alwaysInvokesToStringOnParameter(p) and
|
||||
exists(AssignableDefinitions::ImplicitParameterDefinition def, Parameter p |
|
||||
def.getParameter() = p and
|
||||
alwaysInvokesToString(def.getAFirstRead()) and
|
||||
e = p.getAnAssignedArgument()
|
||||
)
|
||||
}
|
||||
|
||||
pragma[noinline]
|
||||
private predicate alwaysInvokesToStringOnParameter(Parameter p) {
|
||||
exists(AssignableDefinitions::ImplicitParameterDefinition def, ParameterRead pr |
|
||||
def.getParameter() = p and
|
||||
pr = def.getAReachableRead() and
|
||||
pr.getAControlFlowNode().postDominates(p.getCallable().getEntryPoint()) and
|
||||
invokesToString(pr, _)
|
||||
)
|
||||
pragma[nomagic]
|
||||
private predicate parameterReadPostDominatesEntry(ParameterRead pr) {
|
||||
pr.getAControlFlowNode().postDominates(pr.getEnclosingCallable().getEntryPoint())
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate alwaysInvokesToString(ParameterRead pr) {
|
||||
parameterReadPostDominatesEntry(pr) and
|
||||
invokesToString(pr, _)
|
||||
or
|
||||
alwaysInvokesToString(pr.getANextRead())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user