mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
C#: Include CompositeFormat.Parse as Format like method.
This commit is contained in:
@@ -289,3 +289,31 @@ class FormatCall extends MethodCall {
|
||||
result = this.getArgument(this.getFirstArgument() + index)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A method call to a method that parses a format string, for example a call
|
||||
* to `string.Format()`.
|
||||
*/
|
||||
abstract private class FormatStringParseCallImpl extends MethodCall {
|
||||
/**
|
||||
* Gets the expression used as the format string.
|
||||
*/
|
||||
abstract Expr getFormatExpr();
|
||||
}
|
||||
|
||||
final class FormatStringParseCall = FormatStringParseCallImpl;
|
||||
|
||||
private class OrdinaryFormatCall extends FormatStringParseCallImpl instanceof FormatCall {
|
||||
override Expr getFormatExpr() { result = FormatCall.super.getFormatExpr() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A method call to `System.Text.CompositeFormat.Parse`.
|
||||
*/
|
||||
class ParseFormatStringCall extends FormatStringParseCallImpl {
|
||||
ParseFormatStringCall() {
|
||||
this.getTarget() = any(SystemTextCompositeFormatClass x).getParseMethod()
|
||||
}
|
||||
|
||||
override Expr getFormatExpr() { result = this.getArgument(0) }
|
||||
}
|
||||
|
||||
@@ -16,22 +16,6 @@ import semmle.code.csharp.frameworks.system.Text
|
||||
import semmle.code.csharp.frameworks.Format
|
||||
import FormatFlow::PathGraph
|
||||
|
||||
abstract class FormatStringParseCall extends MethodCall {
|
||||
abstract Expr getFormatExpr();
|
||||
}
|
||||
|
||||
class OrdinaryFormatCall extends FormatStringParseCall instanceof FormatCall {
|
||||
override Expr getFormatExpr() { result = FormatCall.super.getFormatExpr() }
|
||||
}
|
||||
|
||||
class ParseFormatStringCall extends FormatStringParseCall {
|
||||
ParseFormatStringCall() {
|
||||
this.getTarget() = any(SystemTextCompositeFormatClass x).getParseMethod()
|
||||
}
|
||||
|
||||
override Expr getFormatExpr() { result = this.getArgument(0) }
|
||||
}
|
||||
|
||||
module FormatInvalidConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node n) { n.asExpr() instanceof StringLiteral }
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ module FormatStringConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
|
||||
|
||||
predicate isSink(DataFlow::Node sink) {
|
||||
sink.asExpr() = any(FormatCall call | call.hasInsertions()).getFormatExpr()
|
||||
sink.asExpr() = any(FormatStringParseCall call).getFormatExpr()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user