Skip to content
Permalink
Browse files
8261131: jcmd jmap dump should not accept gz option with no value
Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
Lin Zang authored and DamonFool committed Feb 25, 2021
1 parent ebdc80e commit aa35b42354bec96c94655b070fbf6d5368bacb77
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@@ -227,7 +227,7 @@ private static void dump(String pid, String options)
// ignore format (not needed at this time)
} else if (subopt.startsWith("gz=")) {
compress_level = subopt.substring("gz=".length());
if (compress_level == null) {
if (compress_level.length() == 0) {
System.err.println("Fail: no number provided in option: '" + subopt + "'");
usage(1);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@@ -118,6 +118,7 @@ public static void main(String[] args) throws Exception {
testDumpLive();
testDumpAll();
testDumpCompressed();
testDumpIllegalCompressedArgs();
}

private static void testHisto() throws Exception {
@@ -230,7 +231,23 @@ private static void testDumpCompressed() throws Exception {
dump(true, false, true);
}

private static void testDumpIllegalCompressedArgs() throws Exception{
dump(true, false, true, "0", 1, "Compression level out of range");
dump(true, false, true, "100", 1, "Compression level out of range");
dump(true, false, true, "abc", 1, "Invalid compress level");
dump(true, false, true, "", 1, "Fail: no number provided in option:");
}

private static void dump(boolean live, boolean explicitAll, boolean compressed) throws Exception {
dump(live, explicitAll, compressed, "1", 0, "Heap dump file created");
}

private static void dump(boolean live,
boolean explicitAll,
boolean compressed,
String compressLevel,
int expExitValue,
String expOutput) throws Exception {
String liveArg = "";
String fileArg = "";
String compressArg = "";
@@ -248,22 +265,24 @@ private static void dump(boolean live, boolean explicitAll, boolean compressed)

String filePath = "jmap.dump" + System.currentTimeMillis() + ".hprof";
if (compressed) {
compressArg = "gz=1,";
compressArg = "gz=" + compressLevel;
filePath = filePath + ".gz";
}

File file = new File(filePath);
if (file.exists()) {
file.delete();
}
fileArg = "file=" + file.getName();
fileArg = "file=" + file.getName() + ",";

OutputAnalyzer output;
allArgs = allArgs + liveArg + compressArg + "format=b," + fileArg;
allArgs = allArgs + liveArg + "format=b," + fileArg + compressArg;
output = jmap(allArgs);
output.shouldHaveExitValue(0);
output.shouldContain("Heap dump file created");
verifyDumpFile(file);
output.shouldHaveExitValue(expExitValue);
output.shouldContain(expOutput);
if (expExitValue == 0) {
verifyDumpFile(file);
}
file.delete();
}

0 comments on commit aa35b42

Please sign in to comment.