2020-06-30 16:59:06 +02:00
include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
2021-02-06 04:10:49 +00:00
The full path of the command is not specified and thus the executable will be searched in all directories listed in the ``++PATH++`` environment variable:
2020-06-30 16:59:06 +02:00
----
2021-02-08 04:09:11 +00:00
Runtime.getRuntime().exec("make"); // Sensitive
Runtime.getRuntime().exec(new String[]{"make"}); // Sensitive
2021-02-12 16:35:24 +01:00
2021-02-08 04:09:11 +00:00
ProcessBuilder builder = new ProcessBuilder("make"); // Sensitive
builder.command("make"); // Sensitive
2020-06-30 16:59:06 +02:00
----
== Compliant Solution
2021-02-06 04:10:49 +00:00
The command is defined by its full path:
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 16:59:06 +02:00
----
2021-02-08 04:09:11 +00:00
Runtime.getRuntime().exec("/usr/bin/make"); // Compliant
Runtime.getRuntime().exec(new String[]{"~/bin/make"}); // Compliant
2021-02-12 16:35:24 +01:00
2021-02-08 04:09:11 +00:00
ProcessBuilder builder = new ProcessBuilder("./bin/make"); // Compliant
builder.command("../bin/make"); // Compliant
builder.command(Arrays.asList("..\bin\make", "-j8")); // Compliant
2021-02-12 16:35:24 +01:00
2021-02-08 04:09:11 +00:00
builder = new ProcessBuilder(Arrays.asList(".\make")); // Compliant
builder.command(Arrays.asList("C:\bin\make", "-j8")); // Compliant
builder.command(Arrays.asList("\\SERVER\bin\make")); // Compliant
2020-06-30 16:59:06 +02:00
----
include::../see.adoc[]
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2023-06-22 10:38:01 +02:00
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]