rspec/rules/S5883/java/rule.adoc

34 lines
719 B
Plaintext
Raw Normal View History

2020-06-30 12:50:28 +02:00
include::../description.adoc[]
== Noncompliant Code Example
----
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
public void runUnsafe(HttpServletRequest request) throws IOException {
String folder = request.getParameter("folder");
String cmd = "mkdir " + folder;
Runtime.getRuntime().exec(cmd); // Noncompliant
}
----
== Compliant Solution
----
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
public void runSafe(HttpServletRequest request) throws IOException {
String folderarg1 = request.getParameter("folder");
String cmd[] = new String[] { "mkdir", folderarg1 };
Runtime.getRuntime().exec(cmd); // Compliant
}
----
include::../see.adoc[]