File tree Expand file tree Collapse file tree 3 files changed +26
-17
lines changed
lib/semmle/code/csharp/frameworks
Security Features/CWE-134 Expand file tree Collapse file tree 3 files changed +26
-17
lines changed Original file line number Diff line number Diff line change @@ -289,3 +289,28 @@ class FormatCall extends MethodCall {
289
289
result = this .getArgument ( this .getFirstArgument ( ) + index )
290
290
}
291
291
}
292
+
293
+ /**
294
+ * A method call to a method that parses a format string, for example a call
295
+ * to `string.Format()`.
296
+ */
297
+ abstract private class FormatStringParseCallImpl extends MethodCall {
298
+ abstract Expr getFormatExpr ( ) ;
299
+ }
300
+
301
+ final class FormatStringParseCall = FormatStringParseCallImpl ;
302
+
303
+ private class OrdinaryFormatCall extends FormatStringParseCallImpl instanceof FormatCall {
304
+ override Expr getFormatExpr ( ) { result = FormatCall .super .getFormatExpr ( ) }
305
+ }
306
+
307
+ /**
308
+ * A method call to `System.Text.CompositeFormat.Parse`.
309
+ */
310
+ class ParseFormatStringCall extends FormatStringParseCallImpl {
311
+ ParseFormatStringCall ( ) {
312
+ this .getTarget ( ) = any ( SystemTextCompositeFormatClass x ) .getParseMethod ( )
313
+ }
314
+
315
+ override Expr getFormatExpr ( ) { result = this .getArgument ( 0 ) }
316
+ }
Original file line number Diff line number Diff line change @@ -15,22 +15,6 @@ import semmle.code.csharp.frameworks.system.Text
15
15
import semmle.code.csharp.frameworks.Format
16
16
import FormatFlow:: PathGraph
17
17
18
- abstract class FormatStringParseCall extends MethodCall {
19
- abstract Expr getFormatExpr ( ) ;
20
- }
21
-
22
- class OrdinaryFormatCall extends FormatStringParseCall instanceof FormatCall {
23
- override Expr getFormatExpr ( ) { result = FormatCall .super .getFormatExpr ( ) }
24
- }
25
-
26
- class ParseFormatStringCall extends FormatStringParseCall {
27
- ParseFormatStringCall ( ) {
28
- this .getTarget ( ) = any ( SystemTextCompositeFormatClass x ) .getParseMethod ( )
29
- }
30
-
31
- override Expr getFormatExpr ( ) { result = this .getArgument ( 0 ) }
32
- }
33
-
34
18
module FormatInvalidConfig implements DataFlow:: ConfigSig {
35
19
predicate isSource ( DataFlow:: Node n ) { n .asExpr ( ) instanceof StringLiteral }
36
20
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ module FormatStringConfig implements DataFlow::ConfigSig {
20
20
predicate isSource ( DataFlow:: Node source ) { source instanceof ActiveThreatModelSource }
21
21
22
22
predicate isSink ( DataFlow:: Node sink ) {
23
- sink .asExpr ( ) = any ( FormatCall call | call . hasInsertions ( ) ) .getFormatExpr ( )
23
+ sink .asExpr ( ) = any ( FormatStringParseCall call ) .getFormatExpr ( )
24
24
}
25
25
}
26
26
You can’t perform that action at this time.
0 commit comments