@@ -4,6 +4,7 @@ import swift
4
4
private import codeql.swift.dataflow.DataFlow
5
5
private import codeql.swift.dataflow.ExternalFlow
6
6
private import codeql.swift.security.SensitiveExprs
7
+ private import codeql.swift.StringFormat
7
8
8
9
/** A data flow sink for cleartext logging of sensitive data vulnerabilities. */
9
10
abstract class CleartextLoggingSink extends DataFlow:: Node { }
@@ -93,30 +94,6 @@ private class CleartextLoggingFieldAdditionalFlowStep extends CleartextLoggingAd
93
94
}
94
95
}
95
96
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
-
120
97
/**
121
98
* A sink that appears to be an imported C `printf` variant.
122
99
*/
@@ -125,7 +102,7 @@ private class PrintfCleartextLoggingSink extends CleartextLoggingSink {
125
102
exists ( CallExpr ce , PrintfFormat f |
126
103
ce .getStaticTarget ( ) = f and
127
104
(
128
- this .asExpr ( ) = ce .getArgument ( f .getFormatParamIndex ( ) ) .getExpr ( ) or
105
+ this .asExpr ( ) = ce .getArgument ( f .getFormatParameterIndex ( ) ) .getExpr ( ) or
129
106
this .asExpr ( ) = ce .getArgument ( f .getNumberOfParams ( ) - 1 ) .getExpr ( )
130
107
) and
131
108
not f .isSprintf ( )
0 commit comments