|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import swift |
| 7 | +import codeql.swift.StringFormat |
7 | 8 | import codeql.swift.dataflow.DataFlow |
8 | 9 | import codeql.swift.dataflow.TaintTracking |
9 | 10 | import codeql.swift.dataflow.FlowSources |
10 | 11 |
|
11 | | -/** |
12 | | - * A function that takes a `printf` style format argument. |
13 | | - */ |
14 | | -abstract class FormattingFunction extends AbstractFunctionDecl { |
15 | | - /** |
16 | | - * Gets the position of the format argument. |
17 | | - */ |
18 | | - abstract int getFormatParameterIndex(); |
19 | | -} |
20 | | - |
21 | | -/** |
22 | | - * An initializer for `String`, `NSString` or `NSMutableString` that takes a |
23 | | - * `printf` style format argument. |
24 | | - */ |
25 | | -class StringInitWithFormat extends FormattingFunction, MethodDecl { |
26 | | - StringInitWithFormat() { |
27 | | - exists(string fName | |
28 | | - this.hasQualifiedName(["String", "NSString", "NSMutableString"], fName) and |
29 | | - fName.matches("init(format:%") |
30 | | - ) |
31 | | - } |
32 | | - |
33 | | - override int getFormatParameterIndex() { result = 0 } |
34 | | -} |
35 | | - |
36 | | -/** |
37 | | - * The `localizedStringWithFormat` method of `String`, `NSString` and `NSMutableString`. |
38 | | - */ |
39 | | -class LocalizedStringWithFormat extends FormattingFunction, MethodDecl { |
40 | | - LocalizedStringWithFormat() { |
41 | | - this.hasQualifiedName(["String", "NSString", "NSMutableString"], |
42 | | - "localizedStringWithFormat(_:_:)") |
43 | | - } |
44 | | - |
45 | | - override int getFormatParameterIndex() { result = 0 } |
46 | | -} |
47 | | - |
48 | | -/** |
49 | | - * The functions `NSLog` and `NSLogv`. |
50 | | - */ |
51 | | -class NsLog extends FormattingFunction, FreeFunctionDecl { |
52 | | - NsLog() { this.getName() = ["NSLog(_:_:)", "NSLogv(_:_:)"] } |
53 | | - |
54 | | - override int getFormatParameterIndex() { result = 0 } |
55 | | -} |
56 | | - |
57 | | -/** |
58 | | - * The `NSException.raise` method. |
59 | | - */ |
60 | | -class NsExceptionRaise extends FormattingFunction, MethodDecl { |
61 | | - NsExceptionRaise() { this.hasQualifiedName("NSException", "raise(_:format:arguments:)") } |
62 | | - |
63 | | - override int getFormatParameterIndex() { result = 1 } |
64 | | -} |
65 | | - |
66 | | -/** |
67 | | - * A call to a function that takes a `printf` style format argument. |
68 | | - */ |
69 | | -class FormattingFunctionCall extends CallExpr { |
70 | | - FormattingFunction target; |
71 | | - |
72 | | - FormattingFunctionCall() { target = this.getStaticTarget() } |
73 | | - |
74 | | - /** |
75 | | - * Gets the format expression used in this call. |
76 | | - */ |
77 | | - Expr getFormat() { result = this.getArgument(target.getFormatParameterIndex()).getExpr() } |
78 | | -} |
79 | | - |
80 | 12 | /** |
81 | 13 | * A taint configuration for tainted data that reaches a format string. |
82 | 14 | */ |
|
0 commit comments