Skip to content

Commit 2664c30

Browse files
committed
Swift: Qhelp / examples.
1 parent 048daa9 commit 2664c30

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

swift/ql/src/experimental/Security/CWE-078/CommandInjection.qhelp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ using it.
2424

2525
<example>
2626
<p>
27-
The following examples execute code from user input without
27+
The following example executes code from user input without
2828
sanitizing it first:
2929
</p>
3030
<sample src="CommandInjectionBad.swift" />
3131
<p>
3232
If user input is used to construct a command it should be checked
3333
first. This ensures that the user cannot insert characters that have special
34-
meanings.
34+
meanings:
3535
</p>
3636
<sample src="CommandInjectionGood.swift" />
3737
</example>
@@ -42,4 +42,4 @@ OWASP:
4242
<a href="https://www.owasp.org/index.php/Command_Injection">Command Injection</a>.
4343
</li>
4444
</references>
45-
</qhelp>
45+
</qhelp>

swift/ql/src/experimental/Security/CWE-078/CommandInjectionGood.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ func validateCommand(_ command: String) -> String? {
66
return nil
77
}
88

9-
var task = Process()
10-
task.launchPath = "/bin/bash"
11-
task.arguments = ["-c", validateCommand(userControlledString)] // GOOD
9+
if let validatedString = validateCommand(userControlledString) {
10+
var task = Process()
11+
task.launchPath = "/bin/bash"
12+
task.arguments = ["-c", validatedString] // GOOD
1213

13-
task.launch()
14+
task.launch()
15+
}

0 commit comments

Comments
 (0)