@@ -173,7 +173,7 @@ class InvalidFormatString extends StringLiteral {
173173}
174174
175175/** Provides a dataflow configuration for format strings. */
176- private module FormatFlow {
176+ module FormatFlow {
177177 private import semmle.code.csharp.dataflow.DataFlow
178178
179179 private class FormatConfiguration extends DataFlow2:: Configuration {
@@ -186,12 +186,21 @@ private module FormatFlow {
186186 }
187187 }
188188
189- predicate hasFlow ( StringLiteral lit , Expr format ) {
190- exists ( DataFlow:: Node n1 , DataFlow:: Node n2 , FormatConfiguration conf |
191- n1 .asExpr ( ) = lit and n2 .asExpr ( ) = format
192- |
193- conf .hasFlow ( n1 , n2 )
194- )
189+ query predicate nodes = DataFlow2:: PathGraph:: nodes / 3 ;
190+
191+ query predicate edges = DataFlow2:: PathGraph:: edges / 2 ;
192+
193+ class PathNode = DataFlow2:: PathNode ;
194+
195+ /**
196+ * Holds if there is flow from string literal `lit` to the format string in
197+ * `call`. `litNode` and `formatNode` are the corresponding data-flow path
198+ * nodes.
199+ */
200+ predicate hasFlowPath ( StringLiteral lit , PathNode litNode , FormatCall call , PathNode formatNode ) {
201+ litNode .getNode ( ) .asExpr ( ) = lit and
202+ formatNode .getNode ( ) .asExpr ( ) = call .getFormatExpr ( ) and
203+ any ( FormatConfiguration conf ) .hasFlowPath ( litNode , formatNode )
195204 }
196205}
197206
@@ -218,10 +227,12 @@ class FormatCall extends MethodCall {
218227 }
219228
220229 /**
230+ * DEPRECATED: Use `FormatFlow::hasFlowPath()` instead.
231+ *
221232 * Gets a format string. Global data flow analysis is applied to retrieve all
222233 * sources that can reach this method call.
223234 */
224- StringLiteral getAFormatSource ( ) { FormatFlow:: hasFlow ( result , this . getFormatExpr ( ) ) }
235+ deprecated StringLiteral getAFormatSource ( ) { FormatFlow:: hasFlowPath ( result , _ , this , _ ) }
225236
226237 /**
227238 * Gets the number of supplied arguments (excluding the format string and format
@@ -245,7 +256,7 @@ class FormatCall extends MethodCall {
245256 /** Gets a supplied argument that is not used in the format string `src`. */
246257 int getAnUnusedArgument ( ValidFormatString src ) {
247258 result = this .getASuppliedArgument ( ) and
248- src = this . getAFormatSource ( ) and
259+ FormatFlow :: hasFlowPath ( src , _ , this , _ ) and
249260 not result = src .getAnInsert ( )
250261 }
251262}
0 commit comments