34 lines
719 B
Plaintext
34 lines
719 B
Plaintext
![]() |
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[]
|