File tree 3 files changed +29
-17
lines changed
lib/semmle/code/csharp/frameworks
Security Features/CWE-134
3 files changed +29
-17
lines changed Original file line number Diff line number Diff line change @@ -289,3 +289,31 @@ 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
+ /**
299
+ * Gets the expression used as the format string.
300
+ */
301
+ abstract Expr getFormatExpr ( ) ;
302
+ }
303
+
304
+ final class FormatStringParseCall = FormatStringParseCallImpl ;
305
+
306
+ private class OrdinaryFormatCall extends FormatStringParseCallImpl instanceof FormatCall {
307
+ override Expr getFormatExpr ( ) { result = FormatCall .super .getFormatExpr ( ) }
308
+ }
309
+
310
+ /**
311
+ * A method call to `System.Text.CompositeFormat.Parse`.
312
+ */
313
+ class ParseFormatStringCall extends FormatStringParseCallImpl {
314
+ ParseFormatStringCall ( ) {
315
+ this .getTarget ( ) = any ( SystemTextCompositeFormatClass x ) .getParseMethod ( )
316
+ }
317
+
318
+ override Expr getFormatExpr ( ) { result = this .getArgument ( 0 ) }
319
+ }
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