Skip to content

Commit 47abcd0

Browse files
committed
Protect stdio from malicious tests
1 parent d42d8f7 commit 47abcd0

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

compiler/test/dotty/tools/vulpix/ChildJVMMain.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,27 @@ private static void runMain(String dir) throws Exception {
4141
}
4242

4343
public static void main(String[] args) throws Exception {
44-
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
44+
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
4545

46-
while (true) {
47-
runMain(stdin.readLine());
48-
System.out.println(MessageEnd);
49-
}
46+
while (true) {
47+
var err = System.err;
48+
var out = System.out;
49+
var in = System.in;
50+
try {
51+
runMain(stdin.readLine());
52+
}
53+
finally {
54+
if (err != System.err) {
55+
System.setErr(err);
56+
}
57+
if (out != System.out) {
58+
System.setOut(out);
59+
}
60+
if (in != System.in) {
61+
System.setIn(in);
62+
}
63+
}
64+
System.out.println(MessageEnd);
65+
}
5066
}
5167
}

0 commit comments

Comments
 (0)