MCPcopy Create free account
hub / github.com/apache/tomcat / run

Method run

java/org/apache/catalina/servlets/CGIServlet.java:1383–1555  ·  view source on GitHub ↗

Executes a CGI script with the desired environment, current working directory, and input/output streams This implements the following CGI specification recommendations: Servers SHOULD provide the " query " component of the script-URI as command-line arguments to scripts

()

Source from the content-addressed store, hash-verified

1381 * @see java.lang.Runtime#exec(String[] command, String[] envp, File dir)
1382 */
1383 protected void run() throws IOException {
1384
1385 /*
1386 * REMIND: this method feels too big; should it be re-written?
1387 */
1388
1389 if (!isReady()) {
1390 throw new IOException(sm.getString("cgiServlet.notReady"));
1391 }
1392
1393 if (log.isTraceEnabled()) {
1394 log.trace("envp: [" + env + "], command: [" + command + "]");
1395 }
1396
1397 if ((command.contains(File.separator + "." + File.separator)) ||
1398 (command.contains(File.separator + "..")) || (command.contains(".." + File.separator))) {
1399 throw new IOException(sm.getString("cgiServlet.invalidCommand", command));
1400 }
1401
1402 Runtime rt;
1403 BufferedReader cgiHeaderReader = null;
1404 InputStream cgiOutput = null;
1405 BufferedReader commandsStdErr = null;
1406 Thread errReaderThread = null;
1407 BufferedOutputStream commandsStdIn;
1408 Process proc = null;
1409 int bufRead = -1;
1410
1411 List<String> cmdAndArgs = new ArrayList<>();
1412 if (!cgiExecutable.isEmpty()) {
1413 cmdAndArgs.add(cgiExecutable);
1414 }
1415 if (cgiExecutableArgs != null) {
1416 cmdAndArgs.addAll(cgiExecutableArgs);
1417 }
1418 cmdAndArgs.add(command);
1419 cmdAndArgs.addAll(params);
1420
1421 try {
1422 rt = Runtime.getRuntime();
1423 proc = rt.exec(cmdAndArgs.toArray(new String[0]), mapToStringArray(env), wd);
1424
1425 String sContentLength = env.get("CONTENT_LENGTH");
1426
1427 if (!"".equals(sContentLength)) {
1428 commandsStdIn = new BufferedOutputStream(proc.getOutputStream());
1429 IOTools.flow(stdin, commandsStdIn);
1430 commandsStdIn.flush();
1431 commandsStdIn.close();
1432 }
1433
1434 /*
1435 * we want to wait for the process to exit, Process.waitFor() is useless in our situation; see
1436 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4223650
1437 */
1438
1439 boolean isRunning = true;
1440 commandsStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));

Callers 1

doGetMethod · 0.95

Calls 15

isReadyMethod · 0.95
mapToStringArrayMethod · 0.95
flowMethod · 0.95
sendToLogMethod · 0.95
getStringMethod · 0.65
isTraceEnabledMethod · 0.65
traceMethod · 0.65
containsMethod · 0.65
addMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected