File tree Expand file tree Collapse file tree
swift/ql/src/experimental/Security/CWE-078 Expand file tree Collapse file tree Original file line number Diff line number Diff 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
2828sanitizing it first:
2929</p >
3030<sample src =" CommandInjectionBad.swift" />
3131<p >
3232If user input is used to construct a command it should be checked
3333first. This ensures that the user cannot insert characters that have special
34- meanings.
34+ meanings:
3535</p >
3636<sample src =" CommandInjectionGood.swift" />
3737</example >
4242<a href =" https://www.owasp.org/index.php/Command_Injection" >Command Injection</a >.
4343</li >
4444</references >
45- </qhelp >
45+ </qhelp >
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments