@@ -4,6 +4,7 @@ import swift
44private import codeql.swift.dataflow.DataFlow
55private import codeql.swift.dataflow.ExternalFlow
66private import codeql.swift.security.SensitiveExprs
7+ private import codeql.swift.StringFormat
78
89/** A data flow sink for cleartext logging of sensitive data vulnerabilities. */
910abstract class CleartextLoggingSink extends DataFlow:: Node { }
@@ -93,30 +94,6 @@ private class CleartextLoggingFieldAdditionalFlowStep extends CleartextLoggingAd
9394 }
9495}
9596
96- /**
97- * A function that appears to be an imported C `printf` variant.
98- * TODO: merge code with similar cases from the format string PR.
99- */
100- private class PrintfFormat extends FreeFunction {
101- int formatParamIndex ;
102- string modeChars ;
103-
104- PrintfFormat ( ) {
105- modeChars = this .getShortName ( ) .regexpCapture ( "(.*)printf.*" , 1 ) and
106- this .getParam ( formatParamIndex ) .getName ( ) = "format"
107- }
108-
109- /**
110- * Gets the index of the format parameter.
111- */
112- int getFormatParamIndex ( ) { result = formatParamIndex }
113-
114- /**
115- * Holds if this `printf` is a variant of `sprintf`.
116- */
117- predicate isSprintf ( ) { modeChars .charAt ( _) = "s" }
118- }
119-
12097/**
12198 * A sink that appears to be an imported C `printf` variant.
12299 */
@@ -125,7 +102,7 @@ private class PrintfCleartextLoggingSink extends CleartextLoggingSink {
125102 exists ( CallExpr ce , PrintfFormat f |
126103 ce .getStaticTarget ( ) = f and
127104 (
128- this .asExpr ( ) = ce .getArgument ( f .getFormatParamIndex ( ) ) .getExpr ( ) or
105+ this .asExpr ( ) = ce .getArgument ( f .getFormatParameterIndex ( ) ) .getExpr ( ) or
129106 this .asExpr ( ) = ce .getArgument ( f .getNumberOfParams ( ) - 1 ) .getExpr ( )
130107 ) and
131108 not f .isSprintf ( )
0 commit comments