diff --git a/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java b/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java index 9bcdd8547f64003fb0154d78d63e4780d941f57d..488edcdeae53eaed8087ab4885e083f3815ba9a6 100644 --- a/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java +++ b/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2017, 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 @@ -63,9 +63,10 @@ public interface HotSpotDiagnosticMXBean extends PlatformManagedObject { * @param outputFile the system-dependent filename * @param live if true dump only live objects * i.e. objects that are reachable from others - * @throws IOException if the outputFile + * @throws IOException if the outputFile already exists, * cannot be created, opened, or written to. * @throws UnsupportedOperationException if this operation is not supported. + * @throws IllegalArgumentException if outputFile does not end with ".hprof" suffix. * @throws NullPointerException if outputFile is null. * @throws SecurityException * If a security manager exists and its {@link diff --git a/src/share/classes/sun/management/HotSpotDiagnostic.java b/src/share/classes/sun/management/HotSpotDiagnostic.java index d2e7b397208789197260a6f9d168e915a273f4d9..dffaafe5524afb1f28c280d905a6aba80aa59c4d 100644 --- a/src/share/classes/sun/management/HotSpotDiagnostic.java +++ b/src/share/classes/sun/management/HotSpotDiagnostic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2017, 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 @@ -32,6 +32,8 @@ import javax.management.ObjectName; import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.VMOption; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Implementation of the diagnostic MBean for Hotspot VM. @@ -41,6 +43,14 @@ public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean { } public void dumpHeap(String outputFile, boolean live) throws IOException { + + String propertyName = "jdk.management.heapdump.allowAnyFileSuffix"; + PrivilegedAction pa = () -> Boolean.parseBoolean(System.getProperty(propertyName, "false")); + boolean allowAnyFileSuffix = AccessController.doPrivileged(pa); + if (!allowAnyFileSuffix && !outputFile.endsWith(".hprof")) { + throw new IllegalArgumentException("heapdump file must have .hprof extention"); + } + SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkWrite(outputFile);