Skip to content

Commit f7ebd13

Browse files
committed
Swift: Corrections.
1 parent 157a782 commit f7ebd13

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

swift/ql/lib/codeql/swift/security/UncontrolledFormatStringQuery.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* Provides a taint-tracking configuration for reasoning about uncontrolled format string
3-
* vulnerabilities.
2+
* Provides a taint-tracking configuration for reasoning about uncontrolled
3+
* format string vulnerabilities.
44
*/
5-
5+
66
import swift
77
import codeql.swift.StringFormat
88
import codeql.swift.dataflow.DataFlow

swift/ql/src/queries/Security/CWE-134/UncontrolledFormatString.qhelp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@
44
<qhelp>
55
<overview>
66
<p>
7-
Passing untrusted format strings to functions that use <code>printf</code> style formatting can lead to buffer overflows and data representation problems. An attacker can exploit this weakness to crash the program or obtain sensitive information from its internal state.</p>
8-
</p>
7+
Passing untrusted format strings to functions that use <code>printf</code> style formatting can lead to buffer overflows and data representation problems. An attacker may be able to exploit this weakness to crash the program or obtain sensitive information from its internal state.</p>
98

109
</overview>
1110
<recommendation>
1211

13-
<p>Use a string literal for the format string to prevent the possibility of data flow from
12+
<p>Use a constant string literal for the format string to prevent the possibility of data flow from
1413
an untrusted source. This also helps to prevent errors where the format arguments do not match the format string.</p>
1514

16-
<p>If the format string cannot be constant, ensure that it comes from a secure data source or is compiled into the source code. If you need to include a value from the user, use the <code>%@</code> specifier in the format string and include that value as a format argument.
15+
<p>If the format string cannot be constant, ensure that it comes from a secure data source or is compiled into the source code. If you need to include a string value from the user, use an appropriate specifier (such as <code>%@</code>) in the format string and include the user provided value as a format argument.
1716
</p>
1817

1918
</recommendation>
2019
<example>
2120

2221
<p>In this example, the format string includes a user-controlled <code>inputString</code>:</p>
2322

24-
<sample src="UncontrolledFormatStringBad.cs" />
23+
<sample src="UncontrolledFormatStringBad.swift" />
2524

2625
<p>To fix it, make <code>inputString</code> a format argument rather than part of the format string, as in the following code:</p>
2726

28-
<sample src="UncontrolledFormatStringGood.cs" />
27+
<sample src="UncontrolledFormatStringGood.swift" />
2928

3029
</example>
3130
<references>

swift/ql/src/queries/Security/CWE-134/UncontrolledFormatString.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ import DataFlow::PathGraph
1717

1818
from TaintedFormatConfiguration config, DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode
1919
where config.hasFlowPath(sourceNode, sinkNode)
20-
select sinkNode.getNode(), sourceNode, sinkNode, "This format string is derived from a $@.",
21-
sourceNode.getNode(), "user-provided value"
20+
select sinkNode.getNode(), sourceNode, sinkNode, "This format string depends on $@.",
21+
sourceNode.getNode(), "a user-provided value"

swift/ql/test/query-tests/Security/CWE-134/UncontrolledFormatString.expected

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ nodes
2121
| UncontrolledFormatString.swift:89:61:89:61 | tainted | semmle.label | tainted |
2222
subpaths
2323
#select
24-
| UncontrolledFormatString.swift:68:28:68:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:68:28:68:28 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
25-
| UncontrolledFormatString.swift:71:28:71:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:71:28:71:28 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
26-
| UncontrolledFormatString.swift:72:28:72:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:72:28:72:28 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
27-
| UncontrolledFormatString.swift:74:28:74:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:74:28:74:28 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
28-
| UncontrolledFormatString.swift:75:28:75:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:75:28:75:28 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
29-
| UncontrolledFormatString.swift:76:28:76:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:76:28:76:28 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
30-
| UncontrolledFormatString.swift:77:46:77:46 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:77:46:77:46 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
31-
| UncontrolledFormatString.swift:86:11:86:11 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:86:11:86:11 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
32-
| UncontrolledFormatString.swift:89:61:89:61 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:89:61:89:61 | tainted | This format string is derived from a $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | user-provided value |
24+
| UncontrolledFormatString.swift:68:28:68:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:68:28:68:28 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
25+
| UncontrolledFormatString.swift:71:28:71:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:71:28:71:28 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
26+
| UncontrolledFormatString.swift:72:28:72:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:72:28:72:28 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
27+
| UncontrolledFormatString.swift:74:28:74:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:74:28:74:28 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
28+
| UncontrolledFormatString.swift:75:28:75:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:75:28:75:28 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
29+
| UncontrolledFormatString.swift:76:28:76:28 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:76:28:76:28 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
30+
| UncontrolledFormatString.swift:77:46:77:46 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:77:46:77:46 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
31+
| UncontrolledFormatString.swift:86:11:86:11 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:86:11:86:11 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |
32+
| UncontrolledFormatString.swift:89:61:89:61 | tainted | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) : | UncontrolledFormatString.swift:89:61:89:61 | tainted | This format string depends on $@. | UncontrolledFormatString.swift:62:24:62:77 | call to init(contentsOf:) | a user-provided value |

swift/ql/test/query-tests/Security/CWE-134/UncontrolledFormatString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
struct URL
55
{
6-
init?(string: String) {}
6+
init?(string: String) {}
77
}
88

99
struct Locale {
@@ -12,7 +12,7 @@ struct Locale {
1212
extension String : CVarArg {
1313
public var _cVarArgEncoding: [Int] { get { return [] } }
1414

15-
init(contentsOf: URL) throws { self.init() }
15+
init(contentsOf: URL) throws { self.init() }
1616
init(format: String, _ arguments: CVarArg...) { self.init() }
1717
init(format: String, arguments: [CVarArg]) { self.init() }
1818
init(format: String, locale: Locale?, _ args: CVarArg...) { self.init() }

0 commit comments

Comments
 (0)