Skip to content

Commit 82b65b6

Browse files
author
Aleksandar Gradinac
committed
[GR-33691] Properly quote arguments passed via argument files
PullRequest: graal/9750
2 parents 1e27d86 + d11728e commit 82b65b6

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.Map;
5151
import java.util.Optional;
5252
import java.util.Properties;
53+
import java.util.StringJoiner;
5354
import java.util.function.BiConsumer;
5455
import java.util.function.BiFunction;
5556
import java.util.function.Consumer;
@@ -1301,7 +1302,22 @@ protected static List<String> createImageBuilderArgs(ArrayList<String> imageArgs
13011302
protected static String createVMInvocationArgumentFile(List<String> arguments) {
13021303
try {
13031304
Path argsFile = Files.createTempFile("vminvocation", ".args");
1304-
String joinedOptions = String.join("\n", arguments);
1305+
StringJoiner joiner = new StringJoiner("\n");
1306+
for (String arg : arguments) {
1307+
// Options in @argfile need to be properly quoted as
1308+
// this relies on the JDK's @argfile parsing when the
1309+
// native image generator is being launched.
1310+
String quoted = SubstrateUtil.quoteShellArg(arg);
1311+
// @argfile rules for Windows quirk: backslashes don't need to be
1312+
// escaped if the option they are used in isn't quoted. If it is
1313+
// though, then they need to be escaped. This might mean that
1314+
// user-supplied arguments containing '\' will be double escaped.
1315+
if (quoted.startsWith("'")) {
1316+
quoted = quoted.replace("\\", "\\\\");
1317+
}
1318+
joiner.add(quoted);
1319+
}
1320+
String joinedOptions = joiner.toString();
13051321
Files.write(argsFile, joinedOptions.getBytes());
13061322
argsFile.toFile().deleteOnExit();
13071323
return "@" + argsFile;

0 commit comments

Comments
 (0)