From b1c34c03d7a84a230b0799f30a420c03ebe89b14 Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Wed, 18 Jan 2023 21:29:57 +0000 Subject: [PATCH] 8296684: Improve String platform support Reviewed-by: amenkov, michaelm, rhalade --- .../classes/sun/tools/attach/VirtualMachineImpl.java | 1 + .../classes/sun/tools/attach/VirtualMachineImpl.java | 1 + .../classes/sun/tools/attach/VirtualMachineImpl.java | 1 + .../sun/tools/attach/HotSpotVirtualMachine.java | 10 ++++++++++ .../classes/sun/tools/attach/VirtualMachineImpl.java | 1 + 5 files changed, 14 insertions(+) diff --git a/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java index 9e00978f250..d0a6dac40c8 100644 --- a/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java @@ -136,6 +136,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // did we detach? synchronized (this) { diff --git a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java index 324e52235cb..6a70d5d9f71 100644 --- a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java @@ -140,6 +140,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // did we detach? synchronized (this) { diff --git a/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java index 7a3b79853e7..891a0561a8a 100644 --- a/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/macosx/classes/sun/tools/attach/VirtualMachineImpl.java @@ -136,6 +136,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // did we detach? synchronized (this) { diff --git a/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java b/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java index 409aa055082..2c2e865a086 100644 --- a/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java +++ b/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java @@ -487,4 +487,14 @@ public abstract class HotSpotVirtualMachine extends VirtualMachine { } return attachTimeout; } + + protected static void checkNulls(Object... args) { + for (Object arg : args) { + if (arg instanceof String s) { + if (s.indexOf(0) >= 0) { + throw new IllegalArgumentException("illegal null character in command"); + } + } + } + } } diff --git a/src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java index f2241c209bb..184d07137e2 100644 --- a/src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java @@ -73,6 +73,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // create a pipe using a random name Random rnd = new Random();