rspec/rules/S4721/java/rule.adoc

41 lines
1.0 KiB
Plaintext
Raw Normal View History

2020-06-30 12:49:37 +02:00
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[]
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::rspecator-view[]