forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
64 lines (48 loc) · 1.58 KB
/
Test.java
File metadata and controls
64 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.lang.ProcessBuilder;
import java.util.List;
import java.util.ArrayList;
class Test {
public static void shellCommand(String arg) throws java.io.IOException {
ProcessBuilder pb = new ProcessBuilder("/bin/bash -c echo " + arg);
pb.start();
pb = new ProcessBuilder(new String[]{"/bin/bash", "-c", "echo " + arg});
pb.start();
List<String> cmd = new ArrayList<String>();
cmd.add("/bin/bash");
cmd.add("-c");
cmd.add("echo " + arg);
pb = new ProcessBuilder(cmd);
pb.start();
String[] cmd1 = new String[]{"/bin/bash", "-c", "<cmd>"};
cmd1[1] = "echo " + arg;
pb = new ProcessBuilder(cmd1);
pb.start();
}
public static void nonShellCommand(String arg) throws java.io.IOException {
ProcessBuilder pb = new ProcessBuilder("./customTool " + arg);
pb.start();
pb = new ProcessBuilder(new String[]{"./customTool", arg});
pb.start();
List<String> cmd = new ArrayList<String>();
cmd.add("./customTool");
cmd.add(arg);
pb = new ProcessBuilder(cmd);
pb.start();
String[] cmd1 = new String[]{"./customTool", "<arg>"};
cmd1[1] = arg;
pb = new ProcessBuilder(cmd1);
pb.start();
}
public static void relativeCommand() throws java.io.IOException {
ProcessBuilder pb = new ProcessBuilder("ls");
pb.start();
pb = new ProcessBuilder("/bin/ls");
pb.start();
}
public static void main(String[] args) throws java.io.IOException {
String arg = args.length > 1 ? args[1] : "default";
shellCommand(arg);
nonShellCommand(arg);
relativeCommand();
}
}