34 lines
912 B
Plaintext
34 lines
912 B
Plaintext
![]() |
include::../description.adoc[]
|
||
|
|
||
|
include::../ask-yourself.adoc[]
|
||
|
|
||
|
include::../recommended.adoc[]
|
||
|
|
||
|
== Sensitive Code Example
|
||
|
|
||
|
----
|
||
|
Runtime.getRuntime().exec("file.exe"); // Sensitive: an absolute path is used
|
||
|
|
||
|
ProcessBuilder pb = new ProcessBuilder("file.exe"); // Sensitive: an absolute path is used
|
||
|
pb.command("file.exe"; // Sensitive.
|
||
|
|
||
|
CommandLine cmdLine = CommandLine.parse("file.exe"); // Sensitive: an absolute path is used
|
||
|
DefaultExecutor executor = new DefaultExecutor();
|
||
|
executor.execute(cmdLine);
|
||
|
----
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
Runtime.getRuntime().exec("/usr/bin/file.exe"); // Compliant
|
||
|
|
||
|
ProcessBuilder pb = new ProcessBuilder("/usr/bin/file.exe"); // Compliant
|
||
|
pb.command("/usr/bin/file.exe"; // Sensitive.
|
||
|
|
||
|
CommandLine cmdLine = CommandLine.parse("/usr/bin/file.exe"); // Compliant
|
||
|
DefaultExecutor executor = new DefaultExecutor();
|
||
|
executor.execute(cmdLine);
|
||
|
----
|
||
|
|
||
|
include::../see.adoc[]
|