File tree Expand file tree Collapse file tree 3 files changed +29
-17
lines changed
lib/semmle/code/csharp/frameworks
Security Features/CWE-134 Expand file tree Collapse file tree 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 {
289289 result = this .getArgument ( this .getFirstArgument ( ) + index )
290290 }
291291}
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 @@ -16,22 +16,6 @@ import semmle.code.csharp.frameworks.system.Text
1616import semmle.code.csharp.frameworks.Format
1717import FormatFlow:: PathGraph
1818
19- abstract class FormatStringParseCall extends MethodCall {
20- abstract Expr getFormatExpr ( ) ;
21- }
22-
23- class OrdinaryFormatCall extends FormatStringParseCall instanceof FormatCall {
24- override Expr getFormatExpr ( ) { result = FormatCall .super .getFormatExpr ( ) }
25- }
26-
27- class ParseFormatStringCall extends FormatStringParseCall {
28- ParseFormatStringCall ( ) {
29- this .getTarget ( ) = any ( SystemTextCompositeFormatClass x ) .getParseMethod ( )
30- }
31-
32- override Expr getFormatExpr ( ) { result = this .getArgument ( 0 ) }
33- }
34-
3519module FormatInvalidConfig implements DataFlow:: ConfigSig {
3620 predicate isSource ( DataFlow:: Node n ) { n .asExpr ( ) instanceof StringLiteral }
3721
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ module FormatStringConfig implements DataFlow::ConfigSig {
2020 predicate isSource ( DataFlow:: Node source ) { source instanceof ActiveThreatModelSource }
2121
2222 predicate isSink ( DataFlow:: Node sink ) {
23- sink .asExpr ( ) = any ( FormatCall call | call . hasInsertions ( ) ) .getFormatExpr ( )
23+ sink .asExpr ( ) = any ( FormatStringParseCall call ) .getFormatExpr ( )
2424 }
2525}
2626
You can’t perform that action at this time.
0 commit comments