Skip to content

Commit

Permalink
8296684: Improve String platform support
Browse files Browse the repository at this point in the history
Reviewed-by: mbalao
Backport-of: 9ae682726873de27cef4d3bd5523713f4ff98266
  • Loading branch information
Olga Mikhaltsova authored and RealCLanger committed Apr 12, 2023
1 parent 04abba8 commit 43dd5ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -143,6 +143,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?
synchronized (this) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2021, 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 @@ -148,6 +148,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?
synchronized (this) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, 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 @@ -143,6 +143,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?
synchronized (this) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2021, 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 @@ -393,4 +393,14 @@ long attachTimeout() {
}
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");
}
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, 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
Random rnd = new Random();
Expand Down

0 comments on commit 43dd5ff

Please sign in to comment.