Skip to content

Commit 6b2e339

Browse files
committed
C#: Address QL review comments.
1 parent 64de748 commit 6b2e339

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

csharp/ql/src/Security Features/CWE-134/UncontrolledFormatString.ql

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@
1313
import csharp
1414
import semmle.code.csharp.dataflow.flowsources.Remote
1515
import semmle.code.csharp.dataflow.TaintTracking
16-
import semmle.code.csharp.frameworks.System
16+
import semmle.code.csharp.frameworks.Format
1717
import DataFlow::PathGraph
1818

19-
class FormatStringConfiguration extends TaintTracking::Configuration
20-
{
19+
class FormatStringConfiguration extends TaintTracking::Configuration {
2120
FormatStringConfiguration() { this = "FormatStringConfiguration" }
2221

2322
override predicate isSource(DataFlow::Node source) {
2423
source instanceof RemoteFlowSource
2524
}
2625

2726
override predicate isSink(DataFlow::Node sink) {
28-
exists(MethodCall call | sink.asExpr() = call.getArgumentForName("format") and
29-
call.getTarget() = any(SystemStringClass s).getFormatMethod()
30-
)
27+
sink.asExpr() = any(FormatCall call).getFormatExpr()
3128
}
3229
}
3330

3431
from FormatStringConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
3532
where config.hasFlowPath(source, sink)
3633
select sink.getNode(), source, sink,
37-
"$@ flows to here and is used to format 'String.Format'.", source.getNode(), source.getNode().toString()
34+
"$@ flows to here and is used as a format string.", source.getNode(), source.getNode().toString()

csharp/ql/test/query-tests/Security Features/CWE-134/UncontrolledFormatString.expected

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ edges
22
| UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | UncontrolledFormatString.cs:14:23:14:26 | access to local variable path |
33
| UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | UncontrolledFormatString.cs:17:46:17:49 | access to local variable path |
44
| UncontrolledFormatStringBad.cs:9:25:9:47 | access to property QueryString | UncontrolledFormatStringBad.cs:12:39:12:44 | access to local variable format |
5+
nodes
6+
| UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString |
7+
| UncontrolledFormatString.cs:14:23:14:26 | access to local variable path |
8+
| UncontrolledFormatString.cs:17:46:17:49 | access to local variable path |
9+
| UncontrolledFormatString.cs:20:23:20:38 | "Do not do this" |
10+
| UncontrolledFormatString.cs:23:46:23:61 | "Do not do this" |
11+
| UncontrolledFormatStringBad.cs:9:25:9:47 | access to property QueryString |
12+
| UncontrolledFormatStringBad.cs:12:39:12:44 | access to local variable format |
513
#select
6-
| UncontrolledFormatString.cs:14:23:14:26 | access to local variable path | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | UncontrolledFormatString.cs:14:23:14:26 | access to local variable path | $@ flows to here and is used to format 'String.Format'. | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | access to property QueryString |
7-
| UncontrolledFormatString.cs:17:46:17:49 | access to local variable path | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | UncontrolledFormatString.cs:17:46:17:49 | access to local variable path | $@ flows to here and is used to format 'String.Format'. | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | access to property QueryString |
8-
| UncontrolledFormatStringBad.cs:12:39:12:44 | access to local variable format | UncontrolledFormatStringBad.cs:9:25:9:47 | access to property QueryString | UncontrolledFormatStringBad.cs:12:39:12:44 | access to local variable format | $@ flows to here and is used to format 'String.Format'. | UncontrolledFormatStringBad.cs:9:25:9:47 | access to property QueryString | access to property QueryString |
14+
| UncontrolledFormatString.cs:14:23:14:26 | access to local variable path | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | UncontrolledFormatString.cs:14:23:14:26 | access to local variable path | $@ flows to here and is used as a format string. | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | access to property QueryString |
15+
| UncontrolledFormatString.cs:17:46:17:49 | access to local variable path | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | UncontrolledFormatString.cs:17:46:17:49 | access to local variable path | $@ flows to here and is used as a format string. | UncontrolledFormatString.cs:11:23:11:45 | access to property QueryString | access to property QueryString |
16+
| UncontrolledFormatStringBad.cs:12:39:12:44 | access to local variable format | UncontrolledFormatStringBad.cs:9:25:9:47 | access to property QueryString | UncontrolledFormatStringBad.cs:12:39:12:44 | access to local variable format | $@ flows to here and is used as a format string. | UncontrolledFormatStringBad.cs:9:25:9:47 | access to property QueryString | access to property QueryString |

0 commit comments

Comments
 (0)