File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed
swift/ql/src/experimental/Security/CWE-078 Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -24,14 +24,14 @@ using it.
24
24
25
25
<example >
26
26
<p >
27
- The following examples execute code from user input without
27
+ The following example executes code from user input without
28
28
sanitizing it first:
29
29
</p >
30
30
<sample src =" CommandInjectionBad.swift" />
31
31
<p >
32
32
If user input is used to construct a command it should be checked
33
33
first. This ensures that the user cannot insert characters that have special
34
- meanings.
34
+ meanings:
35
35
</p >
36
36
<sample src =" CommandInjectionGood.swift" />
37
37
</example >
42
42
<a href =" https://www.owasp.org/index.php/Command_Injection" >Command Injection</a >.
43
43
</li >
44
44
</references >
45
- </qhelp >
45
+ </qhelp >
Original file line number Diff line number Diff line change @@ -6,8 +6,10 @@ func validateCommand(_ command: String) -> String? {
6
6
return nil
7
7
}
8
8
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
12
13
13
- task. launch ( )
14
+ task. launch ( )
15
+ }
You can’t perform that action at this time.
0 commit comments