Skip to content

Commit 09346c7

Browse files
committed
Swift: Add models.
1 parent cb6aed1 commit 09346c7

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
/**
2-
* Provides models for the `UITextField` Swift class.
2+
* Provides models for the `UITextField` and related Swift class.
33
*/
44

55
import swift
66
private import codeql.swift.dataflow.ExternalFlow
77

88
/**
9-
* A model for `UITextField` members that are flow sources.
9+
* A model for `UITextField` and `UITextInput` members that are flow sources.
1010
*/
1111
private class UITextFieldSource extends SourceModelCsv {
1212
override predicate row(string row) {
13-
row = [";UITextField;true;text;;;;local", ";UITextField;true;attributedText;;;;local"]
13+
row =
14+
[
15+
";UITextField;true;text;;;;local", ";UITextField;true;attributedText;;;;local",
16+
";UITextFieldDelegate;true;textField(_:shouldChangeCharactersIn:replacementString:);;;Parameter[2];local",
17+
";UITextViewDelegate;true;textView(_:shouldChangeTextIn:replacementText:);;;Parameter[2];local",
18+
";UITextInput;true;text(in:);;;ReturnValue;local",
19+
";UITextInput;true;shouldChangeText(in:replacementText:);;;Parameter[1];local",
20+
]
1421
}
1522
}

swift/ql/test/library-tests/dataflow/flowsources/uikit.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ class MyTextInput : UITextInput {
5555
func text(in range: UITextRange) -> String? { return nil }
5656
func harmless(in range: UITextRange) -> String? { return nil }
5757

58-
func shouldChangeText(in range: UITextRange, replacementText text: String) -> Bool { // $ MISSING: source=local
59-
sink(arg: text) // $ MISSING: tainted=
58+
func shouldChangeText(in range: UITextRange, replacementText text: String) -> Bool { // $ source=local
59+
sink(arg: text) // $ tainted
6060

6161
return true
6262
}
6363
}
6464

6565
class MyUITextFieldDelegate : UITextFieldDelegate {
66-
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { // $ MISSING: source=local
67-
sink(arg: string) // $ MISSING: tainted=
66+
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { // $ source=local
67+
sink(arg: string) // $ tainted
6868

6969
return true
7070
}
@@ -77,6 +77,6 @@ func test(textField: UITextField, searchTextField: UISearchTextField, myTextInpu
7777
_ = textField.text?.uppercased() // $ source=local
7878
_ = searchTextField.text // $ source=local
7979

80-
_ = myTextInput.text(in: range)! // $ MISSING: source=local
80+
_ = myTextInput.text(in: range)! // $ source=local
8181
_ = myTextInput.harmless(in: range)! // GOOD (not input)
8282
}

0 commit comments

Comments
 (0)