mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
C#: Re-factor UncontrolledFormatString to use the new API.
This commit is contained in:
@@ -15,29 +15,29 @@ import csharp
|
||||
import semmle.code.csharp.security.dataflow.flowsources.Remote
|
||||
import semmle.code.csharp.security.dataflow.flowsources.Local
|
||||
import semmle.code.csharp.frameworks.Format
|
||||
import DataFlow::PathGraph
|
||||
import FormatString::PathGraph
|
||||
|
||||
class FormatStringConfiguration extends TaintTracking::Configuration {
|
||||
FormatStringConfiguration() { this = "FormatStringConfiguration" }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) {
|
||||
module FormatStringConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) {
|
||||
source instanceof RemoteFlowSource
|
||||
or
|
||||
source instanceof LocalFlowSource
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
predicate isSink(DataFlow::Node sink) {
|
||||
sink.asExpr() = any(FormatCall call | call.hasInsertions()).getFormatExpr()
|
||||
}
|
||||
}
|
||||
|
||||
module FormatString = TaintTracking::Global<FormatStringConfig>;
|
||||
|
||||
string getSourceType(DataFlow::Node node) {
|
||||
result = node.(RemoteFlowSource).getSourceType()
|
||||
or
|
||||
result = node.(LocalFlowSource).getSourceType()
|
||||
}
|
||||
|
||||
from FormatStringConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
|
||||
where config.hasFlowPath(source, sink)
|
||||
from FormatString::PathNode source, FormatString::PathNode sink
|
||||
where FormatString::flowPath(source, sink)
|
||||
select sink.getNode(), source, sink, "This format string depends on $@.", source.getNode(),
|
||||
("this" + getSourceType(source.getNode()))
|
||||
|
||||
Reference in New Issue
Block a user