diff --git a/jdk/src/aix/classes/sun/tools/attach/AixVirtualMachine.java b/jdk/src/aix/classes/sun/tools/attach/AixVirtualMachine.java index 29ee0138b4d..280382aecc8 100644 --- a/jdk/src/aix/classes/sun/tools/attach/AixVirtualMachine.java +++ b/jdk/src/aix/classes/sun/tools/attach/AixVirtualMachine.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright 2015 SAP AG. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -134,6 +134,7 @@ public void detach() throws IOException { */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // did we detach? String p; diff --git a/jdk/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java b/jdk/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java index bf2e9516525..ea4f2e28b25 100644 --- a/jdk/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java +++ b/jdk/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -344,4 +344,15 @@ long attachTimeout() { } return attachTimeout; } + + protected static void checkNulls(Object... args) { + for (Object arg : args) { + if (arg instanceof String) { + String s = (String)arg; + if (s.indexOf(0) >= 0) { + throw new IllegalArgumentException("illegal null character in command"); + } + } + } + } } diff --git a/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java b/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java index ad344f1411e..67f3620a243 100644 --- a/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java +++ b/jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -133,6 +133,7 @@ public void detach() throws IOException { */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // did we detach? String p; diff --git a/jdk/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java b/jdk/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java index 9dec425da0d..20fdb5c0dc5 100644 --- a/jdk/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java +++ b/jdk/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -149,6 +149,7 @@ public void detach() throws IOException { */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // did we detach? String p; diff --git a/jdk/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java b/jdk/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java index 3c57e4bda6a..d144600f778 100644 --- a/jdk/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java +++ b/jdk/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -117,6 +117,7 @@ public void detach() throws IOException { */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // first check that we are still attached int door; diff --git a/jdk/src/windows/classes/sun/tools/attach/WindowsVirtualMachine.java b/jdk/src/windows/classes/sun/tools/attach/WindowsVirtualMachine.java index 3b34c0d181a..c0b816a2d22 100644 --- a/jdk/src/windows/classes/sun/tools/attach/WindowsVirtualMachine.java +++ b/jdk/src/windows/classes/sun/tools/attach/WindowsVirtualMachine.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -78,6 +78,7 @@ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null + checkNulls(args); // create a pipe using a random name int r = (new Random()).nextInt();