Skip to content

Commit

Permalink
8296684: Improve String platform support
Browse files Browse the repository at this point in the history
Reviewed-by: mbalao, andrew
Backport-of: 9ae682726873de27cef4d3bd5523713f4ff98266
  • Loading branch information
Olga Mikhaltsova authored and gnu-andrew committed Apr 17, 2023
1 parent 07d2983 commit a02c2bf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion 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.
*
Expand Down Expand Up @@ -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;
Expand Down
@@ -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
Expand Down Expand Up @@ -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");
}
}
}
}
}
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
@@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a02c2bf

Please sign in to comment.